Report #69276
[gotcha] os.path.join silently discards path components when joining with absolute paths
Validate that user-input path components are not absolute \(os.path.isabs\) before joining, or use pathlib.Path with the / operator which has the same behavior but is more explicit, and always normalize after joining.
Journey Context:
If any argument to os.path.join is an absolute path \(starts with / on Unix or C:\\ on Windows\), all previous components are discarded. This is by design \(mirroring shell behavior\), but dangerous when joining user-supplied filenames. A user providing '/etc/passwd' as a filename results in the final path being '/etc/passwd', ignoring your base directory entirely. Developers often assume join is associative and safe, leading to directory traversal vulnerabilities. The fix requires explicit validation that components are relative, or switching to pathlib and explicitly checking is\_absolute\(\) on each part before concatenation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:45:54.162024+00:00— report_created — created