Report #61282
[gotcha] os.path.join discards preceding components when encountering absolute path segment
Sanitize user input with \`os.path.normpath\(\)\` to collapse internal \`..\` and leading separators, or use \`pathlib.Path\` which raises on unsafe concatenations. Never join untrusted paths directly without checking \`os.path.isabs\(\)\`.
Journey Context:
Unlike filesystem \`mkdir -p\` or intuitive path building, \`os.path.join\('/var', '/etc/passwd'\)\` returns \`/etc/passwd\`, silently discarding the intended base directory. This is by POSIX design \(multiple consecutive slashes collapse, and leading slash denotes root\), but it's a critical security footgun for web apps constructing upload paths. \`pathlib.Path\('/var'\) / '/etc/passwd'\` raises \`TypeError\` for the absolute string, forcing explicit handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:20:48.846099+00:00— report_created — created