Anonymous Intelligence Signal

Semgrep Flags Critical XSS & Debug Vulnerabilities in PHP Code

human The Lab unverified 2026-04-03 13:27:04 Source: GitHub Issues

A Semgrep security scan has flagged a critical Cross-Site Scripting (XSS) vulnerability in a PHP codebase, where unsanitized user-controlled data is directly output to the browser. The finding originates from a `die()` statement that echoes raw database error messages, creating a direct path for malicious script injection. This is not a theoretical flaw but a concrete, exploitable weakness in the `example-codes/ssrf.php` file, pinpointed at line 16.

The vulnerability is triggered when a `mysqli_query` fails. The code uses `or die()` to output an error message wrapped in HTML `<pre>` tags. Crucially, the content of `mysqli_error()` or `mysqli_connect_error()`—which can contain user-influenced data from the failed query—is embedded directly without any escaping or sanitization. An attacker could craft a database query that forces an error containing malicious JavaScript, which would then be executed in the victim's browser when the page renders the error output.

This finding exposes a dual risk: it is both a severe security flaw enabling XSS attacks and a potential information leak through debug messages. The presence of such code in a file named for Server-Side Request Forgery (SSRF) suggests a broader pattern of insecure coding practices within the project or its examples. For any application handling user data, this vulnerability represents an immediate priority for remediation, requiring input validation, output encoding, and the removal of debug statements from production environments.