Jump to content

Is $_SERVER[REQUEST_URI] safe to use?


eldan88

Recommended Posts

$_SERVER['REQUEST_URI'] has the same issue as $_SERVER['PHP_SELF']. If the requested URL contains any xss scripting in it and you blindly echo it out on a page back to the browser without using htmlentities/htmlspecialchars on it, then the xss scripting in it will be sent as is to the browser.

 

You must always treat external data (anything received with the http request, even the URL itself) as dangerous and must filter/validate it if you are going to output it back to any browser.

 

To simplify the answer, if you want to output the value of $_SERVER['REQUEST_URI'] to the browser, you're completely safe if you reference it like this:

 

htmlspecialchars($_SERVER['REQUEST_URI'])

 

That will sanitize any characters that might be used to perform an XSS attack.

 

Keep in mind, if you're using a special character set, you need to define that in the function's call... check out the manual for more details: htmlspecialchars

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.