Code injection vulnerability with $ _POST vars?

I wonder if I have a vulnerability with respect to the code below in the fwrite file?

foreach($_POST as $key=>$val) {
    fwrite($fh, "\nPOST variable named " . $key . " has the value " . $val);
}

Should I somehow sanitize the values ​​before they are written to the log file?

UPDATE fh - log file handler

+5
source share
3 answers

There is no vulnerability if the log file is processed by its consumers as plain text (which should always be).

HTML-, (, , ). "" , HTML htmlspecialchars, , .

+3

, $fh. $fh HTML, . , - .

htmlspecialchars(..) HTML.

UPDATE

, :

  • ( public_html, )
  • - text/html ,
+3

XSS (Cross-Site Scripting) ( HTML, ). , - .

+2
source

All Articles