{"id":"GHSA-88g4-74f3-63x9","title":"phpMyFAQ has Potential Authenticated Path Traversal in PDF Export","summary":"phpMyFAQ has Potential Authenticated Path Traversal in PDF Export","severity":"medium","cvss":4.9,"cwe":["CWE-22"],"vendor":"thorsten","product":"thorsten/phpmyfaq","ecosystem":"composer","affected":["thorsten/phpmyfaq >= 4.0.0-alpha, <= 4.1.4","phpmyfaq/phpmyfaq >= 4.0.0-alpha, <= 4.1.4"],"patched":["thorsten/phpmyfaq 4.1.5","phpmyfaq/phpmyfaq 4.1.5"],"published":"2026-08-25","updated":"2026-08-25","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-88g4-74f3-63x9","references":[{"url":"https://github.com/thorsten/phpMyFAQ/security/advisories/GHSA-88g4-74f3-63x9"},{"url":"https://github.com/thorsten/phpMyFAQ/commit/91ce64405479933d7d62c751fa79c2f5c6fda591"},{"url":"https://github.com/thorsten/phpMyFAQ/commit/b709ebe69405385785c2a74ae940c3e8d4cd0a8b"},{"url":"https://github.com/advisories/GHSA-88g4-74f3-63x9"}],"tags":["ghsa","composer"],"ingestedAt":"2026-08-25T18:30:21.584Z","slug":"GHSA-88g4-74f3-63x9","body":"## Overview\n\n## Summary\n\nThere is an authenticated path traversal condition in the PDF export functionality, specifically within the PDF image resolution logic.\n\nThe issue may allow a privileged FAQ editor to cause the application to attempt reading files outside the intended content directory during PDF generation.\n\n---\n\n## Affected Component\n\n**File:**\n`src/phpMyFAQ/Export/Pdf/Wrapper.php`\n\n**Function:**\n`concatenatePaths()`\n\n---\n\n## Root Cause\n\nThe path resolution logic relies on locating the substring `\"content\"` within a user-controlled path:\n\n```php\n$pos = strpos($trimmedFile, 'content');\n$relativePath = substr($trimmedFile, (int) $pos);\n```\n\nIf `\"content\"` is not present, `strpos()` returns `false`, which becomes `0` when cast to an integer.\n\nAs a result, the entire attacker-controlled path is preserved.\n\nExample:\n\n```php\n$trimmedFile = \"../../../etc/passwd\";\n$pos = false;\n$relativePath = \"../../../etc/passwd\";\n```\n\nThe resulting path is later processed by:\n\n```php\nfile_get_contents($resolvedPath);\n```\n\nwithout canonicalization or a root-directory containment check.\n\n---\n\n## Observed Data Flow\n\n```text\nFAQ Content\n    ->\nPDF Export\n    ->\nWriteHTML()\n    ->\nWrapper::Image()\n    ->\nconcatenatePaths()\n    ->\nfile_get_contents()\n```\n\n---\n\n## Potential Impact\n\nBased on code review, a user with FAQ editing privileges may be able to store HTML containing crafted image paths that are processed during PDF generation.\n\nPotential consequences may include:\n\n- Path traversal outside the intended content directory\n- Local file read attempts during PDF export\n- Possible disclosure of readable files depending on file type, sanitization behavior, and PDF rendering constraints\n\n---\n\n## Discovery Method\n\nThis issue was initially detected by an internally developed SAST tool during analysis of the phpMyFAQ source code.\n\nThe finding was then manually investigated and validated through code review.\n\nWhile the original scanner output classified the issue as a generic path traversal/local file inclusion pattern, manual analysis identified the specific root cause in the path resolution logic of `concatenatePaths()`.\n\n---\n\n## Potential Exploitation Scenario\n\nThe following scenario is based on code review and intended to illustrate the potential impact:\n\n1. A user with FAQ editing privileges creates or modifies a FAQ entry.\n\n2. The FAQ content contains an HTML image tag with a crafted relative path that does not include the expected `content` directory reference.\n\n3. The HTML content is stored and later processed by the PDF export functionality.\n\n4. When a user requests the PDF version of the FAQ, the application invokes `WriteHTML()`, which eventually reaches `Wrapper::Image()`.\n\n5. `concatenatePaths()` constructs a filesystem path without canonicalization or directory containment validation.\n\n6. The resulting path reaches `file_get_contents()`, causing the application to attempt reading a file outside the intended content directory.\n\n7. Depending on sanitization behavior, file permissions, image validation, and PDF rendering behavior, the contents of the targeted file may potentially be exposed to the PDF consumer.\n\nBased on my current analysis, exploitation would require a user capable of editing FAQ content and is therefore not considered an anonymous or unauthenticated attack vector.\n\n---\n\n## Suggested Remediation\n\nConsider replacing substring-based path anchoring with:\n\n- `realpath()` canonicalization\n- Strict root-directory containment checks\n- Explicit allowlisting of permitted image locations\n\n## Affected packages\n\n- `thorsten/phpmyfaq >= 4.0.0-alpha, <= 4.1.4`\n- `phpmyfaq/phpmyfaq >= 4.0.0-alpha, <= 4.1.4`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `thorsten/phpmyfaq 4.1.5`\n- `phpmyfaq/phpmyfaq 4.1.5`","depth":"sunlit","depthScore":27,"depthScoreParts":{"impact":27,"likelihood":0,"exploitation":0,"ransomware":0},"changes":[]}