fix(backend): harden request-id/sandbox middleware and limit user response fields - #1133
Open
zoffunjunior381-jpg wants to merge 1 commit into
Open
Conversation
…ponse fields - Validate X-Request-ID against a safe alphanumeric+hyphen charset before echoing/logging it, falling back to randomUUID() to prevent log injection - Add regression test confirming sandbox mode cannot be flipped via header when globally disabled - Add explicit Prisma select clause to GET /v1/users/:publicKey limiting the response to the public user shape - Document the database seed script and its fixtures in the backend README Closes LabsCrypt#1016 Closes LabsCrypt#1017 Closes LabsCrypt#1018 Closes LabsCrypt#1019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
X-Sandbox-Modeheader cannot flipreq.sandbox/req.sandboxModeto true while sandbox mode is globally disabled. Verified the existing middleware already short-circuits correctly in this case (no behavior change needed).requestIdMiddlewarenow validates an incomingX-Request-IDheader against a safe alphanumeric+hyphen character set (in addition to the existing length check) before echoing it back and logging it, falling back torandomUUID()on failure. Added a test covering a header containing a newline plus one with other control/special characters.backend/README.mddocumenting thenpm run prisma:seedcommand and the exact fixturesprisma/seed.tscreates (two demo users, one demo stream, one demo stream event).GET /v1/users/:publicKey(getUserinuser.controller.ts) now uses an explicit Prismaselectclause limiting the response to the public user shape (id,publicKey,createdAt,updatedAt, plus explicitly-selected fields onsentStreams/receivedStreams) instead of returning the full row viainclude. Added a regression test asserting the query usesselect(notinclude) and that internal-only fields are absent from the response.Test plan
npx vitest run tests/sandbox.middleware.test.ts tests/requestId.test.ts tests/user.controller.test.ts— all passnpx tsc --noEmit— no new errors introduced by this change (pre-existing unrelated errors insoroban-indexer.service.ts,soroban-event-worker.ts, and a few test files are out of scope)npm test— 4 pre-existing integration test files fail due to requiring a live Postgres database in this environment; unrelated to this change and out of scopeCloses #1016
Closes #1017
Closes #1018
Closes #1019