DirectoryIterator class silently truncates after a null byte
The DirectoryIterator class in the SPL extension parsed its constructor argument with the wrong type specifier, so a path containing a null byte was treated as a plain string that ends at that byte. An attacker could use this to slip past path-based checks or list a directory they should not be able to reach.
- Triaged in 5 hours
- Fixed in 7 months
- Paid in 7 months
- Disclosed after 8 months
The bug submitted at: https://bugs.php.net/bug.php?id=78863 The security advisory at: https://nvd.nist.gov/vuln/detail/CVE-2019-11045
There's an issue with SPL PHP extension on spl_filesystem_object_construct() function. When creating a new DirectoryIterator() object spl_filesystem_object_construct() function is called and use zend to parse its arguments with the wrong parameter type specifier, this bug leads the zend_parse_parameters() to interprete the parameter as a simple string instead of a filesystem path. An attacker may leverage this by crafting a path name containing NULL bytes which will be badly parsed, allowing the attacker eventually by pass any path-based security validation or listing documents from a unexpected directory.
This flaw has a high Confidentiality impact as the actor may eventually seen the filesystem tree from the attacked machine but a high complexity as the attacker may need to have previous knowledge of filesystem organization or trick the user to run the malicious script.
Impact
In PHP versions 7.2.x below 7.2.26, 7.3.x below 7.3.13 and 7.4.0, PHP DirectoryIterator class accepts filenames with embedded \0 byte and treats them as terminating at that byte. This could lead to security vulnerabilities, e.g. in applications checking paths that the code is allowed to access.
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 constructor used a plain string type specifier when parsing its argument instead of a path type, so the null byte truncated the value before any path validation saw it.
Impact
An attacker could bypass path-based security validation or list files from an unexpected directory, though the text notes this needs prior knowledge of the filesystem layout or a tricked user running the script.
What the attacker needed
Ability to supply a crafted path; knowledge of target filesystem layout
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.
A null byte is a character with value zero that some programming languages use to mark the end of a piece of text. If one part of a program stops reading at that character but another part keeps going, the two can disagree about which file is meant. Here the directory-listing class stopped at the null byte, so a check that approved one path could end up opening a different one.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.