/ THE IDEA
On many systems, a double-dot path component means move to the parent folder. An absolute path starts from a system-defined root rather than the program’s chosen base. Different separators, encodings and platform rules can make a raw text check misleading. Canonicalization resolves alternative spellings into a standard representation according to the relevant filesystem rules. A containment check must then compare real path components with the permitted root, not just test whether the text starts with a familiar sequence. A directory named downloads-private can share the text prefix downloads without being inside it. Links can also redirect a path to another location. The enforcement method must match what the operating system will actually open, including these indirections and any concurrent changes.
THE FORMAL IDEA
permitted = resolved target is inside the allowed directory
| Resolved means interpreted using the applicable path and filesystem rules. | | Inside refers to directory ancestry, not a text-prefix match. The rule describes an access decision, so it has no numerical units. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Toy allowed directory: /srv/downloads/. Request guide.pdf → /srv/downloads/guide.pdf: inside. Change request to ../private/notes.txt → /srv/private/notes.txt: outside; reject. Request ../downloads-private/a.txt also resolves outside despite its similar-looking prefix.
|
The requested text changed where the program would look, even though the download feature itself did not change. A good test examines the final target and the operation, not merely the number of dots or whether a filename ends in an approved extension.
/ SO WHAT?
An even narrower interface lets users request an opaque document identifier and maps it to an application-owned path. The caller chooses among authorised documents rather than supplying filesystem instructions. The process account should also lack access to unrelated private material wherever practical, giving a second boundary if the mapping fails.
ONE CAVEAT |
| Canonicalizing and checking a name before opening can still suffer races if an attacker can change links or directories between those steps. Use platform facilities that enforce confinement during resolution and opening, not a homemade universal path filter. |
KEEP THIS
A safe file boundary constrains the location actually opened, not just the appearance of the filename received.
|
NEXT: Why slowing a neutron can make it more useful
|