User-controllable input must be sanitized before it's included in output used to dynamically generate a web page. Unsanitized user input can introduce cross-side scripting (XSS) vulnerabilities that can lead to inadvertedly running malicious code in a trusted context.
1function nonCompliant() {
2 $name = $_REQUEST['name'];
3 // Noncompliant: '$name' statement is non-compliant as it can leave the application vulnerable to cross-site scripting attacks.
4 echo "Hello :".$name;
5}
1function compliant() {
2 $name = $_REQUEST['name'];
3 // Compliant: 'htmlentities' provides a compliant way to display user input safely.
4 print("Hello : " . htmlentities($name));
5}