Add Path.safe_join/2 - #15720
Merged
Merged
Conversation
Member
|
💚 💙 💜 💛 ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Path traversal via unsafe path composition is a well-known class of bug (CWE-22, and part of OWASP Top 10 A01:2025 Broken Access Control). It typically occurs when a trusted root is combined with an externally-supplied segment that is assumed to be a safe relative path.
Path.safe_relative/2already exists to validate such segments, but pairing it withjoin/2at every call site is boilerplate that is easy to omit.Path.safe_join/2makes the safe pattern a one-liner. It validates right viasafe_relative/2and joins it to left.Only a /2 version is provided. A list-based /1 variant was considered and rejected because it has no clear trust boundary. With
[root, a, b, c]it is ambiguous which segments are trusted and which need validation. Callers who need to compose a trusted prefix should do so explicitly.