Skip to content

fix(#45): harden download endpoints against path traversal#46

Open
linisha15 wants to merge 1 commit intoOSeMOSYS:masterfrom
linisha15:fix/45-path-traversal-downloads
Open

fix(#45): harden download endpoints against path traversal#46
linisha15 wants to merge 1 commit intoOSeMOSYS:masterfrom
linisha15:fix/45-path-traversal-downloads

Conversation

@linisha15
Copy link

Description:

Summary
This PR fixes #45 by preventing path traversal in all file download routes.

Changes

  • Added strict validation for request path segments (rejects empty values, separators, and traversal values)
  • Added resolved-path containment checks using Path.resolve() and Path.is_relative_to()
  • Return 400 Bad Request for invalid/traversal file paths
  • Preserve 404 Not Found behavior for missing files

Endpoints updated

  • /downloadDataFile
  • /downloadFile
  • /downloadCSVFile
  • /downloadResultsFile

File changed

  • DataFileRoute.py

Security impact

  • Blocks traversal payloads such as ../../../...
  • Ensures resolved file path stays inside the intended base directory before serving files

Validation

  • No diagnostics errors in the updated file
  • Invalid/traversal paths now return 400
  • Missing files continue to return 404

Closes #45

@Sameer-00001
Copy link

Sameer-00001 commented Mar 17, 2026

Screenshot 2026-03-17 193445 Hey @linisha15 Looks great! This correctly implements the pathlib containment check we discussed in Issue #45. Verified locally and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(SECURITY BUG) Path Traversal Vulnerability in Download Endpoints

2 participants