Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How "tamper proof" is the $_SERVER variable in php?

Would I be taking a big security risk by trusting the content of the $_SERVER variable array to get the name of php file using $_SERVER['PHP_SELF']?

like image 261
CLJ Avatar asked Nov 22 '10 16:11

CLJ


1 Answers

Many but not all of the $_SERVER variables are attacker controlled. For instance $_SERVER['SCRIPT_NAME'] is safe where as $_SEVER['PHP_SELF'] is a vary dangerous variable and is often the source of xss:

<?php
echo $_SEVER['PHP_SELF'];
?>

PoC:

http://localhost/self.php/<script>alert(/xss/)</script>

It is easy to see this vulnerability in action by looking at phpinfo.

like image 181
rook Avatar answered Oct 06 '22 19:10

rook