PHP builded for Windows with TS support does not resolve relalative paths with drive letter correctly
A thread-safe PHP build on Windows mishandles drive-relative paths such as a drive letter followed by a filename without a separator, treating them as rooted on the drive instead of relative to the current directory. An attacker who controls a path that an application validates as staying inside its working directory could therefore read or write files elsewhere on the same drive, including the user's Startup folder.
- Triaged in 3 days
- Fixed in 8 months
- Paid in 8 months
- Disclosed after 9 months
Currently PHP process Windows paths like C:Users as if they were absolute. But they are not and PHP builded with TS (thread-safe support) currently points to root drive location instead of the current directory. This gives the attaker unlimited access to the root drive if a) the path is resolved/normalized by the app before used b) permissions are denied (but on Windows the system files are almost always accessible)
Reported to PHP: https://bugs.php.net/bug.php?id=78939 https://github.com/php/php-src/pull/5001
Impact
Attaker can get access to all files on the same drive if the path is validated by some middleware correctly but PHP then points to bad location.
Example scenario:
- PHP pwd:
C:/Web/uploads - path:
C:secret_data.txt - apps checks if the path is within pwd - yes, it is, correct resolved location should be
C:/Web/uploads/secret_data.txt - but PHP accesses
C:/secret_data.txt
If app can write with user supplied path, the path can be handcrafted to point to location like C:\Users\<USER>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup and inject malicious file to be started when the user logs in.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the thread-safe Windows path handling in PHP does not treat a drive-letter path without a following separator as drive-relative, resolving it against the drive root instead of the current directory.
Impact
An attacker could read or write any file on the same drive when an application validates the path but PHP resolves it to the wrong location, and could plant a file in the Startup folder to run code at login; the text notes that on Windows system files are almost always accessible.
What the attacker needed
Thread-safe PHP build on Windows; app accepts user-supplied paths; app validates path before use
The fix
The report links to a PHP bug entry and a pull request, but does not state that a fix was released.
How it was found
- Set the PHP working directory to a folder on a drive.
- Supply a path consisting of the drive letter followed directly by a filename, with no separator.
- Observe that the application's check sees the path as inside the working directory.
- Observe that PHP actually opens the file at the root of the drive instead.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
On Windows, a path that starts with a drive letter but no backslash after it is meant to be relative to whatever folder you are currently in on that drive. This report says a particular PHP build instead jumps to the top of the drive, so a file the application thought was inside its own upload folder is actually read from somewhere else. If an attacker can choose the path, they may reach files they should not, or plant a file that runs at login.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.