Summary
An arbitrary file upload vulnerability in the AddFont() function of FPDF v1.86 and earlier allows attackers to upload crafted PHP files to the server.
When the uploaded files are placed in a web-accessible directory and executed by the PHP interpreter, this can lead to remote code execution under the web server's privileges.
Affected context
This vulnerability appears in PHP applications that integrate FPDF v1.86 or earlier and expose functionality that ultimately calls AddFont() with user-influenced data.
It becomes especially risky when:
- Uploaded font definition files are stored in directories served by the web server, and
- The application or library does not enforce strict file type and extension checks, and
- PHP code in uploaded files can be executed by the interpreter.
Not all deployments will be affected in the same way; the risk depends on how and where generated or uploaded files are stored and executed.
Exploit preconditions
- Attack surface: Web-facing endpoints or features that invoke FPDF's AddFont() and allow users to upload or influence font files.
- Required access: Ability to interact with the vulnerable endpoint (often unauthenticated or low-privileged authenticated access, depending on the application).
- Trigger point: Uploading a crafted PHP file through the AddFont() workflow so that it is stored as part of the font assets.
- Why exploitation is possible: The AddFont() handling insufficiently restricts or validates the uploaded file type, content, and extension, allowing executable PHP code to be saved in a location that can later be invoked via HTTP.
Why this happens
The underlying flaw maps to CWE-434: Unrestricted Upload of File with Dangerous Type.
The AddFont() function, as used in affected setups, does not adequately validate or sanitize user-controlled file uploads, allowing files with executable content (e.g., PHP code) to be stored on the server.
Instead of enforcing a strict allowlist of safe file types, validated extensions, and non-executable storage locations, the logic trusts the provided file, treating it as a font definition.
This trust boundary failure between user input and server-side file system operations enables attackers to plant server-side scripts that the PHP runtime can execute.
Potential impact
- Remote execution of arbitrary PHP code on the server
- Full compromise of the affected web application
- Access to or modification of application data and configuration
- Use of the compromised server as a pivot point for further network attacks
- Installation of backdoors or web shells for persistent access
- Defacement or manipulation of generated PDF content and related assets
General mitigation guidance
Effective mitigation generally focuses on constraining file uploads and separating executable code from user-controlled content:
- Enforce a strict allowlist of permitted file types for any AddFont()-related uploads, validating both MIME type and file extension server-side.
- Verify file content signatures (e.g., checking for expected font definition formats) rather than relying solely on filenames or client-side checks.
- Store any user-controlled or dynamically generated files outside of web-accessible directories and ensure they are not interpreted as PHP or other executable code.
- Disable script execution (e.g., via web server configuration) in directories where uploads or generated assets are stored.
- Apply least-privilege to the web server's filesystem permissions so uploaded content cannot overwrite code or sensitive configuration.
- Centralize and reuse hardened upload handlers instead of ad-hoc file handling logic around FPDF.
How teams detect issues like this
To detect and monitor for this class of issue, organizations can:
- Use static application security testing (SAST) to flag calls that:
- Write user-controlled data to the filesystem, and
- Use FPDF AddFont() or similar APIs without strict validation or path controls.
- Add code review checkpoints for any file upload workflows, ensuring reviewers look for:
- Lack of content validation and extension checks
- Storage of user files under webroot or executable directories
- Direct use of user input in filesystem paths
- Enable runtime application security monitoring to detect anomalous requests that:
- Access uploaded files with .php or other executable extensions
- Invoke newly created scripts or unusual URLs under upload directories
- Periodically scan the webroot and upload directories for unexpected executable files using security tools or custom scripts.

