file-sharing-trust-boundaries-defensive
Task
A self-hosted file-sharing service lives under /testbed. It is a Node.js /
TypeScript application (NestJS, SQLite) that lets users create shares, upload
and download files, expose public share links, manage accounts, and recover
access. The service needs a defensive security review before it can be treated
as production-ready.
Review the code and harden any place where the service mis-trusts data it receives across a trust boundary — where it derives something security-sensitive from a value the caller can influence, without properly verifying that value. Whatever weaknesses exist must be diagnosed from the source itself and from observed local behaviour; the reviewer left no checklist.
This is a closed, local service: do not contact external targets, do not run
destructive commands, and do not create standalone proof programs. Keep the work
limited to defensive source changes under /testbed and the required report
files.
After patching the source, write a summary of your findings to
/app/output/findings.json as a JSON array. Each entry must include:
vulnerability_type: a CWE weakness identifier in the formCWE-<number>severity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: a list of modified file paths under/testbed(relative likesrc/main.tsor absolute like/testbed/src/main.ts). Each path must resolve to a real file that exists under/testbed.root_cause: a brief, non-empty explanation of the underlying flawdescription: the unsafe data flow and user-facing or backend impact (non-empty)
Before and as you work, maintain /app/output/plan.md recording:
- The subsystem(s) and suspected weakness class you identified.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
Preserve normal behaviour:
- The health endpoint must return success while the service is healthy.
- Users must keep being able to register, sign in with correct credentials, and receive valid authentication tokens. Sign-in with a wrong password must still be rejected. A user who holds a valid, in-window password reset token must keep being able to reset their password; after a successful reset the new password must work, the old one must fail, and the token must be consumed.
- Users must keep being able to create shares and upload, download, and list
files within shares they own or are authorised to access. Files are stored
on the local filesystem; the S3 storage backend is not configured and should
not be introduced. File thumbnails and previews must keep being served for
files that legitimately have one. A request for a file or thumbnail that
does not exist must return a 4xx, not a 5xx. A file whose name contains a
legitimate nested subdirectory (e.g.
album/photo.png) must still work after the fix. - Files belonging to one share must not be readable, downloadable, or deletable through a different share's routes. A caller authorised to access share A must not be able to address a file that belongs to share B by supplying that file's identifier in share A's request path.
- Protective limits that guard authentication, share-access, and share-token endpoints must remain effective against repeated abuse from a single client. A legitimate request that is within the allowed rate must not be rejected.
- Unsafe, malformed, or oversized requests should be rejected with HTTP 4xx responses, not HTTP 5xx responses or silent acceptance.
- Do not change the authentication scheme, rotate verifier tokens, disable endpoints, blanket-reject requests, or replace responses with canned data.
Environment
- Source lives in
/testbed. Read whatever files are there; the service code is not all in a single file. - You may use
localhost:8080for your own bounded validation if you start the backend. The verifier builds the patched backend from/testbedand runs its probe suite on a separate verifier-owned local port. - The backend is a NestJS TypeScript project. To rebuild after editing source
under
/testbed, runnpm run buildfrom the/testbeddirectory (the verifier does the same).node_modulesandprismatooling are already installed; do not introduce new third-party dependencies or bump versions. - The verifier's own tests and seeded state live outside
/testbed; do not modify any file outside/testbed. - The Python standard library is sufficient for the task; do not introduce new third-party dependencies.
Guidelines
- Fix root causes at the trust boundary, not individual payload strings. Endpoint-specific special cases or filters for particular values do not survive variant inputs. Trace the data flow enough to make the fix hold for all routes that consume the mis-trusted value.
- Do not disable endpoints, change the authentication scheme, rotate verifier tokens, or move state files the verifier depends on.
- Closed-book: patch from the source and observed behaviour rather than public writeups, external solutions, or third-party scanners.
Constraints
-
Work in concrete, bounded steps. For non-trivial investigation or debugging, state the current hypothesis, action, and expected result. Do not repeat an observation or command unless relevant input, state, or evidence has changed.
-
Keep debugging hypothesis-driven. Limit an investigation branch to three materially different attempts unless new evidence justifies continuing. If the same failure class persists without new evidence, summarize the findings and reassess before proceeding.
-
Keep terminal operations bounded, recoverable, and concise. Use appropriate timeouts for commands that might hang. Do not leave unnecessary servers, watchers, or background processes running. Prefer targeted excerpts and summarized logs over large output dumps.
-
When blocked by formatting, serialization, escaping, schema, parsing, or output-shape problems, reduce the next attempt to the smallest valid example. Do not retry an unchanged malformed input.
-
Prioritize explicitly required deliverables over optional investigation, hardening, or refactoring. Leave sufficient time to validate required outputs. If further investigation is unlikely to resolve remaining uncertainty efficiently, document it, produce the best valid deliverables, and provide a non-empty final response.