Skip to content

Return the validated real path from SafePath::getPath - #676

Open
ziyziy89 wants to merge 1 commit into
meta:mainfrom
ziyziy89:safepath-return-realpath
Open

ziyziy89 wants to merge 1 commit into
meta:mainfrom
ziyziy89:safepath-return-realpath

Conversation

@ziyziy89

Copy link
Copy Markdown

With useRealPaths set, SafePath::getPathSafe and the allowlist overload of SafePath::getPath check realpath(filePath) against the base directory or allowlist, but return the lexical cleanPath result. The two disagree when a symlink inside the base is followed by ..: with base /srv/www and /srv/www/assets -> /srv/www/static/v2/assets, the input /srv/www/assets/../../secret.txt resolves to /srv/www/static/secret.txt and passes the check, while the returned path is /srv/secret.txt. A file outside the base can be reached this way whenever a file exists at the mirrored path inside it (for example one a client uploaded).

Return the path that was actually validated: the real path when useRealPaths is set, the normalized path otherwise (unchanged). Keeping this inside SafePath means the checked path and the opened path are the same string, so callers don't have to re-validate.

Verified by building the unmodified SafePathUtils.cpp with g++ against small folly/fmt shims and a directory link: before the change both overloads return and open the out-of-base file, after it they return the in-base file, and ordinary lookups are unaffected. I could not run the full getdeps build on this machine.

With useRealPaths set, getPathSafe and the allowlist overload of getPath
check realpath(filePath) but returned the lexically normalized path.
The two differ when a symlink inside the base directory is followed by
"..", so the caller could open a file outside the base. Return the path
that was checked.
@meta-cla meta-cla Bot added the CLA Signed label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant