I am having code vulnerability in a opensource project i am working on.
The vulnerability is: Filesystem function dirname() detected with dynamic parameter directly from user input.
Full code of my class is available here
What i am trying is getting website url with following two methods,
//get protocol whether it is secured or plain
public static function websiteProtocol()
{
return (isset($_SERVER['HTTPS']) && (!empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http');
}
And then, get url like this,
public static function websiteUrl()
{
return self::websiteProtocol() . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/';
}
Now, as i am using dirname() with a $_SERVER variable, the PHP code sniffer throws a high vulnerability i mentioned above.
How to resolve this? I have tried to create $dir = dirname($_SERVER['PHP_SELF']);
and replace it in websiteUrl method but it is the same error as i am still using $_SERVER['PHP_SELF']
as a parameter of dirname()
method.
I cant remove the method websiteUrl as it fetches the website url that allows my project to be deployed anywhere with just one modification in config file.
I have also created issue on my repository
Any help here or direct PR on my repo appreciated.
Comments
Post a Comment