Cross-site scripting High

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.

Detector ID
php/cross-site-scripting@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

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}

Compliant example

1function compliant() {
2    $name = $_REQUEST['name'];
3    // Compliant: 'htmlentities' provides a compliant way to display user input safely.
4    print("Hello : " . htmlentities($name));
5}