Skip to content

Add Path.safe_join/2 - #15720

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
maennchen:jm/path-safe-join
Aug 7, 2026
Merged

Add Path.safe_join/2#15720
josevalim merged 1 commit into
elixir-lang:mainfrom
maennchen:jm/path-safe-join

Conversation

@maennchen

Copy link
Copy Markdown
Member

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/2 already exists to validate such segments, but pairing it with join/2 at every call site is boilerplate that is easy to omit.

Path.safe_join/2 makes the safe pattern a one-liner. It validates right via safe_relative/2 and 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.

@josevalim
josevalim merged commit 5e7cb9a into elixir-lang:main Aug 7, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@maennchen
maennchen deleted the jm/path-safe-join branch August 7, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants