Skip to content

fix: safely handle Content-Disposition download filenames - #237

Draft
ryanduguid wants to merge 6 commits into
XeroAPI:masterfrom
ryanduguid:audit/safe-content-disposition-filenames
Draft

fix: safely handle Content-Disposition download filenames#237
ryanduguid wants to merge 6 commits into
XeroAPI:masterfrom
ryanduguid:audit/safe-content-disposition-filenames

Conversation

@ryanduguid

@ryanduguid ryanduguid commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • parse quoted and RFC 2231 encoded Content-Disposition filenames with the standard-library MIME parser
  • extract relative leaves using both POSIX and Windows separators
  • reject absolute, drive, UNC, control, invalid and Windows-reserved names
  • resolve and contain the final path under the configured temporary directory
  • write through an already-open private temporary file and claim the requested leaf with an atomic same-directory hard link, preserving the random path if the name exists or the filesystem cannot make the link
  • avoid name-based cleanup after a failed claim, so a concurrent replacement is never removed
  • add adversarial traversal, encoded/quoted, malformed-header, reserved-name, control-character, regular-file preservation, injected race/replacement and symlink regressions

This SDK contains generated client code. The same hardening should also be carried into Xero's customised Python API-client template before the next regeneration.

Validation

@ryanduguid
ryanduguid marked this pull request as draft August 12, 2026 17:49
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.

1 participant