Skip to content

fix: path traversal for tus#1039

Open
ferhatelmas wants to merge 1 commit intomasterfrom
ferhat/tus-path-traversal
Open

fix: path traversal for tus#1039
ferhatelmas wants to merge 1 commit intomasterfrom
ferhat/tus-path-traversal

Conversation

@ferhatelmas
Copy link
Copy Markdown
Member

@ferhatelmas ferhatelmas commented Apr 21, 2026

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

File backend prevents path traversal via #818 and #883 but TUS with file backend has still the same problem.

What is the new behavior?

Extract secure path helper from file backend and protect upload ids for TUS uploads.

Additional context

Add file backend to integration tests.
Add concurrency control into delete expired and guard for zero offset where it would delete complete uploads if expiration is given and gc was called.
Remove exposes more info about error now.

Copilot AI review requested due to automatic review settings April 21, 2026 14:50
@ferhatelmas ferhatelmas requested a review from a team as a code owner April 21, 2026 14:50
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 21, 2026

Coverage Report for CI Build 24742179298

Coverage increased (+0.1%) to 70.064%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 14 uncovered changes across 2 files (91 of 105 lines covered, 86.67%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
src/storage/protocols/tus/file-store.ts 84 71 84.52%
src/storage/backend/secure-path.ts 20 19 95.0%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/internal/database/tenant.ts 2 82.47%

Coverage Stats

Coverage Status
Relevant Lines: 9777
Covered Lines: 7229
Line Coverage: 73.94%
Relevant Branches: 5459
Covered Branches: 3446
Branch Coverage: 63.13%
Branches in Coverage %: Yes
Coverage Strength: 379.2 hits per line

💛 - Coveralls

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR closes a remaining path traversal gap for TUS uploads when using the file backend by centralizing secure filesystem path resolution and applying it to TUS upload IDs, plus adding integration/unit coverage for the new behavior.

Changes:

  • Extracted path traversal protection into a shared resolveSecureFilesystemPath() helper and reused it in the file backend.
  • Updated the TUS file store to resolve upload paths securely (and added new unit tests around traversal protection / expiry cleanup).
  • Expanded TUS integration coverage to run against both S3 and file backends, including a traversal regression test.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/tus.test.ts Refactors/extends integration tests to cover both backends and adds a file-backed traversal regression test.
src/storage/protocols/tus/file-store.ts Adds secure path resolution for file-backed TUS uploads and expands datastore functionality (create/read/write/remove/getUpload/deleteExpired).
src/storage/protocols/tus/file-store.test.ts New unit tests validating traversal protection and deletion/expiry behavior for the file-backed TUS store.
src/storage/backend/secure-path.ts New shared helper that validates and safely resolves user-controlled relative paths under a fixed root.
src/storage/backend/secure-path.test.ts Unit tests for the new secure path helper.
src/storage/backend/index.ts Re-exports the secure path helper from the backend package.
src/storage/backend/file.ts Replaces inlined traversal logic with the shared secure path helper.
src/storage/backend/file.test.ts Removes the old resolveSecurePath unit suite now covered by secure-path.test.ts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/protocols/tus/file-store.ts
Comment thread src/test/tus.test.ts
Comment thread src/test/tus.test.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR closes a path traversal gap in the TUS implementation when using the file backend by centralizing secure filesystem path resolution and adding regression coverage for both file and S3 TUS flows.

Changes:

  • Extracted a shared resolveSecureFilesystemPath() helper and reused it in the file backend.
  • Hardened the TUS file store implementation (file backend) and expanded TUS integration tests to run against both S3 and file backends.
  • Added targeted unit/integration tests covering traversal rejection and TUS file-store expiration behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/tus.test.ts Refactors TUS integration tests to run for both backends and adds a file-backed traversal regression test.
src/storage/protocols/tus/file-store.ts Adds secure path resolution for file-backed TUS uploads plus custom implementations for read/write/remove/getUpload/deleteExpired.
src/storage/protocols/tus/file-store.test.ts Adds unit tests for traversal protection and deleteExpired behavior/concurrency.
src/storage/backend/secure-path.ts Introduces shared secure path resolver to prevent traversal.
src/storage/backend/secure-path.test.ts Adds unit tests for secure path resolver edge cases.
src/storage/backend/index.ts Re-exports the new secure-path helper.
src/storage/backend/file.ts Replaces inline secure-path logic with the shared helper.
src/storage/backend/file.test.ts Removes the old resolveSecurePath unit suite (covered by secure-path tests now).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/protocols/tus/file-store.ts
Comment thread src/storage/protocols/tus/file-store.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR closes a remaining path traversal vector in the TUS implementation when using the file backend by centralizing secure path resolution and applying it to TUS upload IDs, with expanded test coverage for both S3 and file-backed TUS flows.

Changes:

  • Extracts a shared resolveSecureFilesystemPath() helper and reuses it in FileBackend and the TUS FileStore.
  • Hardens file-backed TUS datastore operations (create/read/write/remove/getUpload/deleteExpired) against traversal and adds concurrency limiting for expired-upload cleanup.
  • Expands/modernizes TUS integration tests to cover both backends, resumable behavior, deletion, and a traversal regression test.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/tus.test.ts Refactors TUS integration tests to run against S3 + file backends; adds resumable/delete + traversal coverage.
src/storage/protocols/tus/file-store.ts Applies secure path resolution to file-backed TUS IDs; adds read/write/remove/getUpload/deleteExpired implementations and concurrency limiting.
src/storage/protocols/tus/file-store.test.ts Adds focused unit tests for traversal protection and expiration cleanup behavior in TUS FileStore.
src/storage/backend/secure-path.ts Introduces shared secure path resolver for user-controlled filesystem paths.
src/storage/backend/secure-path.test.ts Adds unit tests for secure path resolver behavior and rejection cases.
src/storage/backend/index.ts Re-exports the new secure path helper.
src/storage/backend/file.ts Replaces inline secure path logic with the shared helper.
src/storage/backend/file.test.ts Removes the old FileBackend-only resolveSecurePath unit tests (now covered by secure-path tests).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/backend/secure-path.ts Outdated
Comment thread src/test/tus.test.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a remaining path traversal vulnerability in TUS uploads when using the file backend by extracting the existing secure-path logic into a shared helper and applying it to TUS upload IDs, alongside expanded integration/unit test coverage for both S3 and file-backed TUS flows.

Changes:

  • Extracted filesystem path traversal prevention into resolveSecureFilesystemPath() and reused it in the file backend and TUS file store.
  • Hardened file-backed TUS datastore operations (create/read/write/remove/getUpload/deleteExpired) to validate upload IDs and added concurrency limiting in expiration GC.
  • Expanded integration/unit tests to cover file backend TUS flows (upload/resume/delete) and explicit traversal attempts.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/test/tus.test.ts Refactors/expands TUS integration tests to run against both S3 and file backends; adds traversal regression test.
src/storage/protocols/tus/file-store.ts Adds secure-path resolution for upload IDs and implements/remaps several datastore methods + concurrent deleteExpired.
src/storage/protocols/tus/file-store.test.ts Adds focused unit tests for traversal protection and deleteExpired behaviors.
src/storage/backend/secure-path.ts New shared helper for secure path resolution under a fixed root.
src/storage/backend/secure-path.test.ts Unit tests for the new secure path helper.
src/storage/backend/index.ts Re-exports the new secure-path helper.
src/storage/backend/file.ts Replaces duplicated secure-path logic with the shared helper.
src/storage/backend/file.test.ts Removes old resolveSecurePath unit tests (now covered by secure-path.test.ts).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/tus.test.ts
Comment thread src/test/tus.test.ts
Comment thread src/storage/backend/secure-path.ts
Comment thread src/storage/protocols/tus/file-store.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a remaining path traversal risk when using TUS uploads with the file backend by centralizing secure filesystem path resolution and applying it consistently to TUS upload IDs.

Changes:

  • Extracted a shared resolveSecureFilesystemPath() helper and reused it in the file backend and TUS file store.
  • Hardened the TUS file store to validate/resolve upload paths safely and added concurrency control + safer cleanup behavior for expired uploads.
  • Expanded test coverage: TUS integration now runs against both S3 and file backends, plus new focused unit tests for secure-path and the TUS file store.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/test/tus.test.ts Refactors TUS integration tests to run for both S3 and file backends; adds file-backed traversal regression coverage.
src/storage/protocols/tus/file-store.ts Applies secure path resolution to TUS file operations; adds safer deleteExpired behavior with bounded concurrency.
src/storage/protocols/tus/file-store.test.ts Adds unit tests covering traversal rejection, remove semantics, and deleteExpired behavior/concurrency.
src/storage/backend/secure-path.ts Introduces shared secure path resolver to prevent traversal and invalid path inputs.
src/storage/backend/secure-path.test.ts Adds unit tests for secure path resolver behavior and error shaping.
src/storage/backend/index.ts Re-exports the new secure path helper.
src/storage/backend/file.ts Replaces inline secure-path logic with the shared helper.
src/storage/backend/file.test.ts Removes old resolveSecurePath unit tests now covered by secure-path tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/tus.test.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the TUS implementation (especially for the file backend) against path traversal by reusing the same secure path resolution logic already applied in the file backend, and expands test coverage to cover both file and S3 backends plus traversal scenarios.

Changes:

  • Extracts a shared resolveSecureFilesystemPath() helper and reuses it in the file backend and TUS FileStore.
  • Updates TUS FileStore to resolve upload paths securely and adds safer/controlled expired-upload cleanup behavior.
  • Expands TUS integration/unit tests to cover file backend behavior, resumability, deletion, and traversal rejection.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/test/tus.test.ts Refactors TUS integration tests to run against both S3 and file backends; adds resume/delete and traversal test coverage.
src/storage/protocols/tus/file-store.ts Secures upload path resolution for file-backed TUS and adds concurrency-limited expired upload cleanup.
src/storage/protocols/tus/file-store.test.ts Adds focused unit tests for FileStore traversal protection and GC behavior.
src/storage/backend/secure-path.ts Introduces shared secure filesystem path resolver used for user-controlled relative paths.
src/storage/backend/secure-path.test.ts Adds unit tests validating traversal/absolute-path/null-byte rejection semantics.
src/storage/backend/index.ts Re-exports the new secure path helper from the backend module.
src/storage/backend/file.ts Replaces inline secure-path logic with the extracted helper.
src/storage/backend/file.test.ts Removes now-redundant unit tests that directly targeted the prior inline secure-path implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/tus.test.ts
Comment thread src/storage/protocols/tus/file-store.ts Outdated
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
@ferhatelmas ferhatelmas force-pushed the ferhat/tus-path-traversal branch from 483cca1 to 3bde24c Compare April 21, 2026 19:29
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.

4 participants