Skip to content

test: cover attachment traversal and symlink containment - #185

Open
nirmalhk7 wants to merge 3 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/agrinet-upload-containment
Open

nirmalhk7 wants to merge 3 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/agrinet-upload-containment

Conversation

@nirmalhk7

@nirmalhk7 nirmalhk7 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The attachment-containment fix is now part of main through #191: upload basenames are server-generated UUIDs, only validated extensions are retained, and exclusive writes refuse existing destinations. This PR preserves that implementation and adds focused filesystem regressions.

The remaining diff is one test file, backend/__tests__/messages.test.js. Coverage checks:

  • A traversal filename cannot change an outside sentinel; stored bytes remain under uploads and original filename/type metadata survives.
  • A generated-name collision preserves the existing file and does not persist a message.
  • Live and dangling destination symlinks are refused without changing or creating outside files, replacing the link, or persisting a message.

Current main at 92cd98394ab830569b6316d7c2570ed4a8d2e48c was incorporated through an append-only merge. Production source, safe-extension behavior, owner-authorized downloads, conversation deletion and retry behavior match main. All three PR commits carry DCO sign-offs, and the hosted DCO check passes.

Validation rechecked on November 13, 2026, at b3970af0dce5c10d978be8218a9411d49a148969:

  • cd backend && npm test: 71 Node tests pass, one optional Redis integration test skips because its explicit service configuration is absent; all 86 Jest tests across 27 suites pass.
  • Targeted message and attachment-storage suites: all 8 tests pass.
  • A controlled regression restoring client-derived paths and ordinary writes corrupts the outside sentinel and fails the traversal assertion. Removing exclusive creation causes both new symlink cases to fail. Controls ran only in an isolated temporary copy.
  • JavaScript syntax checks, hardcoded-URL check and patch whitespace checks pass.

Filesystem behavior is real; database persistence is doubled in the focused tests. This revision does not claim live DynamoDB, Redis integration or deployment verification. The PR is non-draft, conflict-free and ready for independent human review. Hosted backend regression, CodeQL and hardcoded-URL checks await maintainer authorization; local passing results do not replace those gates.

The contribution follows the fork/PR and per-commit DCO requirements in NTARI's Bug-Build-Test guide. No runtime or conformance binding changes are included. The author must not merge the PR.

Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
@nirmalhk7
nirmalhk7 marked this pull request as ready for review November 11, 2026 23:10
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
@nirmalhk7 nirmalhk7 changed the title Prevent message attachments from overwriting backend files test: cover attachment traversal and symlink containment Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Resolved #185's integration conflicts in b3970af0dce5c10d978be8218a9411d49a148969.

#191 already merged the production containment fix. This branch now preserves main's UUID filenames, validated extensions, exclusive writes, ownership-authorized downloads and current retry/deletion behavior. Its diff against main is only backend/__tests__/messages.test.js, adding traversal, regular-file collision, live-symlink and dangling-symlink regressions.

Verification on this head:

  • cd backend && npm test: 71 Node tests passed; one optional Redis integration test skipped as configured. All 86 Jest tests passed across 27 suites.
  • cd backend && node --test __tests__/messages.test.js __tests__/attachmentStorage.test.js: 8 tests passed.
  • node --check backend/models/message.js and node --check backend/__tests__/messages.test.js: passed.
  • ./scripts/list-hardcoded-urls.sh: passed, no hardcoded localhost URLs.
  • git diff --check: passed.

The traversal regression failed with outside-sentinel corruption under a controlled restoration of client-derived paths and nonexclusive writes. Both symlink tests failed when exclusive creation was removed. Those controls ran in a separate temporary copy; production source on this branch matches main. Focused tests use real filesystem operations and doubled persistence, with no live DynamoDB or deployment claim. The branch was updated without rewriting published history. Hosted checks and maintainer review still need to complete.

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