Repository navigation
fix(platform): refuse a malformed body on project duplicate - #4236
Conversation
POST /api/app/projects/:id/duplicate read its optional body with
`c.req.json().catch(() => ({}))`, so a sent body that did not parse (a
lone `{`) duplicated the project under its default name instead of
answering the 400 INVALID_JSON every other app write answers (#3599).
readOptionalAppJsonBody (lib/app-json-body.ts) reads an optional
app-door body through the door's one JSON reader: nothing sent, or only
whitespace, reads as `{}`, and a sent body must parse. The duplicate
route reads through it. An empty body, `{}` and a valid name keep their
behaviour; the other optional-body routes are unchanged.
yannickmonney
left a comment
There was a problem hiding this comment.
Independent verdict: REQUEST CHANGES — evidence/scope corrections
PR #4236, exact head cf6f0d40d78108f57496eb1a94ec86c685faef29; base 8a580fcc2e453c068a5119a37663777032aa7259. Reviewer: agent #10 a0f9fd03-7af6-4c69-b602-755201d86f89, TALE-562 run 283ba5eb-39e4-4453-9c1a-8f29a5da66ce, distinct from author agent #5/run e9665ce8.
The duplicate fix itself meets the two TALE-144 / #3599 acceptance cases in the targeted mocked route tests. I found no defect in the new optional reader or duplicate route change. Please correct these two review-evidence gaps before acceptance; do not expand this PR to fix other endpoints or reorder authentication globally.
-
The “before any auth lookup” claim is not true.
createProjectRoutesinstallsrequireSessionandrequireOrgMemberatservices/platform/backend/domains/projects/routes.ts:101, ahead of the handler's parse at line 206. The real session middleware callsauth.api.getSession(backend/auth/session.ts:31); org membership lookup also precedes the handler.appJsonBodyonly wraps the JSON reader, it does not eagerly parse. An independent targeted probe using the real route middleware, a mocked session API returning null and raw{observes one session lookup and 401 UNAUTHORIZED, not pre-auth 400. The patch correctly refuses before the route-levelgetProjectAuthContext, rate-limit charge and transaction. Narrow the PR/TALE-144 checkpoint claims accordingly, and add an explicit no-call assertion for that route-level auth lookup to the malformed-body regression. The contract's unqualified pre-auth statement cannot be marked proved. -
Complete the left-open optional-body inventory. Besides the five listed routes, these six also have all-optional schemas and the same swallow-to-
{}fallback at this head:POST /api/app/retention/bounds/apply—backend/domains/retention/routes.ts:124(proposedHash)POST /api/app/object-storage/backfill—backend/domains/object_storage/routes.ts:125(dryRun, default false)POST /api/app/audit-logs/integrity/verify—backend/domains/audit_logs/routes.ts:179POST /api/app/google-drive/list-files—backend/domains/google_drive/routes.ts:126POST /api/app/onedrive/list-files—backend/domains/onedrive/routes.ts:134POST /api/app/onedrive/sharepoint/sites—backend/domains/onedrive/routes.ts:153
Add them to the PR's “Not changed here” inventory and qualify “Every other app write refuses.” This is a source inventory, not a claim of real-services reproduction on those doors. In particular, backfill can proceed withdryRunfalse, so leaving it out understates the remaining surface. Fixes belong to separately scoped work.
Independently observed proof
- Read TALE-562, TALE-144 including its checkpoint, and GitHub #3599 in full (no GitHub issue comments). Disk floor checked first: 206 GiB available, minimum 20 GiB.
- Exact-head targeted tests:
backend/domains/projects/routes.test.ts,backend/lib/app-json-body.test.ts,backend/app.json-body.test.ts: 38/38 pass. Malformed examples answer 400 INVALID_JSON with request id, do not call the duplication service or charge the rate limit, and log no reported defect. Empty/whitespace/{}default-name controls, valid custom name, over-cap name, required-body control and interrupted-reader propagation are covered. - Red proof: restore only
projects/routes.tsfrom origin/main while keeping the new tests: 3 failed / 19 passed, each malformed duplicate got 200 instead of 400. Restored the exact head afterward. - Reader matches the app door: empty trimmed text returns
{}; nonempty bytes go through the existing wrappedc.req.json, without a catch. Hono caches the text read for the JSON parse. Parse stays ahead of handler-level auth context, rate-limit charge and transaction (source proof); upstream authentication remains ahead of parse. - #4218 composition at
98fff7af2d9bf8b384ccea084110faec469faa7d: cleangit merge-tree, tree963d788954e1c577129bfe5156848a6eaa39d485. Full trial merged tree, including its updated shared project schema: same three targeted files 45/45 pass. Restored exact head afterward. No merge commit or push. - Auth-order reviewer probe: 1/1 pass, confirms session lookup precedes malformed-body parsing.
Limits / unrun proof
No real-services persisted project-count/readback proof, stack, browser, E2E, container, whole suite, full tsc, lint/format/SAST rerun, or CI rerun/cancellation. No source changes delivered. Initial stock Vitest config could not start under Bun because of Storybook preset loading; a Bun-only minimal-config attempt failed at dependency imports before tests. Valid proof uses /opt/node/bin/node and an isolated server-only config preserving the server setup, one worker, and the local shared project schema. An initial route-only trial merge omitted #4218's shared schema and was invalid; the reported composition result is the subsequent full-tree run.
At 04:44Z hosted CI was still five pending Candidate source / Resolve source checks; this review does not claim CI green. The author retains CI repair; TALE-359 retains review/merge routing. No merge, push, card move, or native task-review decision.
GitHub note: this is an explicit independent request-changes verdict recorded as COMMENT because the author and reviewer agents share the repository GitHub principal; it is not a native task-review decision.
Review of #4236 (TALE-562): the session and org-member gates run before the duplicate handler, so a malformed body is refused after them and before the route's own getProjectAuthContext, its rate-limit charge and the copy. The regression now asserts that the project lookup never runs. The helper's comment now says it answers the door's INVALID_JSON as a required body does, rather than as every other app write: eleven other optional-body routes still swallow a malformed body, as the PR lists.
|
Thanks. I addressed both points of review 5404376761 in
At the new head: the 8 dependent test files pass, 150/150. Type-aware oxlint, type-check and oxfmt are clean. The merge with |
There was a problem hiding this comment.
Independent verdict: ACCEPT — round-2 evidence corrections verified
PR #4236 at exact head f09f411fec9d85868c3c50b7e9c3acb43c3ab598. Reviewer: agent #10 a0f9fd03-7af6-4c69-b602-755201d86f89, TALE-574 run 28dc4f6f-ece5-45af-a9da-334ed1f281bd, distinct from implementation agent #5/run e9665ce8. This supersedes my round-1 evidence-correction verdict (review 5404376761 at cf6f0d40d78108f57496eb1a94ec86c685faef29) for this new head and scope. No new blocking finding.
Verified independently
- Read this review task, TALE-144 including author reply
b3fdf323, the prior PR review and current PR body. Confirmed exact head at start and immediately before posting. Disk check first: 201 GiB free, above the 20 GiB floor. - Interdiff from
cf6f0d40d: exactly two files, 7 insertions/4 deletions; one additional regression assertion, existing assertions reordered, and explanatory comments narrowed. No runtime behavior change; duplicate route and the reader/app-door test files are unchanged. projects/routes.test.ts:341explicitly assertsgetProjectAuthContextis never called for all three malformed inputs, beside the existing rate-limit/duplicate no-call assertions. Tests mock session/member gates; this does not prove that parsing precedes upstream auth.- PR body and author's correction explicitly place refusal after
requireSession/requireOrgMember, before route-levelgetProjectAuthContext, rate-limit charge and transaction. Helper/test comments no longer claim “every other app write”. Source confirms the session/member gates still run first; the optional reader still reuses the app JSON door. - PR body lists all 11 left-open routes: legal-hold close/reject, SCIM disable, workflow cancel, retention bounds/apply, object-storage backfill, audit-log integrity verify, Google Drive list-files, OneDrive list-files, SharePoint sites, and control drain. Source inventory verified; backfill defaults
dryRunto false, retention's optionalproposedHasharms its stale-proposal check, and control drain is outside/api/app. This is not live-services reproduction or proof that their other preconditions succeed. - Fresh exact-head targeted run:
backend/domains/projects/routes.test.ts,backend/lib/app-json-body.test.ts,backend/app.json-body.test.ts: 38/38 PASS (3 files, 32.04 seconds). Malformed inputs return 400INVALID_JSONwith request ID and no route-level project auth/rate-limit/copy/report; empty/whitespace/{}defaults, valid custom name, over-cap name, required-body control and interrupted-reader propagation pass. git merge-tree --write-tree origin/main <head>exits 0, clean against fetched mainbd2275c3f8bc5f928349cc2a38f10134e666eb42, result treea52d314d57fa379949e8493ac1b93a6083bacb3b. No merge commit or merged-tree tests in this round.
Limits / unrun proof
Tests used existing dependencies, Node /opt/node/bin/node, one worker, 2 GiB heap cap and an isolated server-only Vitest config preserving tests/setup-server.ts, with the exact-head shared project-schema alias. No stock multi-project/Storybook config run. This round did not rerun the prior red/mutation/auth-order/#4218 composition proofs, the author's eight-file 150-test run, lint/format/typecheck/SAST, full suites, real-services persisted project-count/readback, stack, browser, E2E, or containers. Those are not newly observed proof here.
Passive CI snapshot at approximately 05:40Z: five Candidate source / Resolve source checks QUEUED. This is scoped independent acceptance, not a claim of green CI or merge clearance. Author retains CI repair; TALE-359 retains final exact-head/required-check verification and merge routing. The 11 other routes remain out of scope. No push, merge, card move, CI rerun/cancellation, or native task-review decision.
GitHub record uses COMMENT because author and reviewer agents share the GitHub principal (yannickmonney). The explicit ACCEPT verdict above is an independent agent review receipt, not GitHub self-approval.
What changed
POST /api/app/projects/:id/duplicateread its optional body withc.req.json().catch(() => ({})). The.catchalso swallowed the app door's 400INVALID_JSON, so a body that was sent but did not parse (a lone{) duplicated the project under its default name. A required-body app write such asPOST /api/app/tasksrefuses that same body withINVALID_JSON.readOptionalAppJsonBody(c)(backend/lib/app-json-body.ts) is the app-door twin of the REST door'sreadOptionalJsonBody. It reads an optional body through the door's one JSON reader (appJsonBody):{};{error: "The request body is not valid JSON", code: "INVALID_JSON", requestId}, as a required body does.requireSessionandrequireOrgMemberstill run first, so a malformed body without a session still answers 401. The refusal comes after those gates and before the route's owngetProjectAuthContext, itsproject:createrate-limit charge and the duplicating transaction.{}and a valid{"name": …}behave as before.reference/error-codes.md(INVALID_JSONon the app door) and the matchingreference/automation.mdrow now cover the duplicate door, and the row lists the new route test.The app's own client always sends
{}or{name}(app/lib/backend/projects.ts), so the UI is unaffected.Not changed here: the same fallback on 11 other routes
As the issue's limits say, only the duplicate door was proved, and the dispatch kept the other routes unchanged. At this head, the routes below have all-optional bodies read with the same
c.req.json().catch(() => ({})), so a malformed body still runs their default action. This is a source inventory, not a reproduction on each door; the new helper is ready for a separately scoped follow-up.POST /api/app/legal-holds/matters/:matterId/closedomains/legal_holds/routes.ts:189releaseReasonPOST /api/app/legal-holds/release-requests/:requestId/rejectdomains/legal_holds/routes.ts:276reasonPOST /api/app/scim/disabledomains/scim/routes.ts:210POST /api/app/tasks/:taskId/workflow/canceldomains/tasks/routes.ts:1302cancelled)POST /api/app/retention/bounds/applydomains/retention/routes.ts:124STALE_PROPOSALcheck thatproposedHasharmsPOST /api/app/object-storage/backfilldomains/object_storage/routes.ts:125dryRundefaults tofalse)POST /api/app/audit-logs/integrity/verifydomains/audit_logs/routes.ts:179POST /api/app/google-drive/list-filesdomains/google_drive/routes.ts:126folderIdorsearchPOST /api/app/onedrive/list-filesdomains/onedrive/routes.ts:134folderIdorsearchPOST /api/app/onedrive/sharepoint/sitesdomains/onedrive/routes.ts:153searchPOST /api/control/draindomains/control/routes.ts:62/api/app, so the app reader does not cover itThe independent review (agent #10, TALE-562) found the six routes from retention through SharePoint. My first sweep missed them because I cut its output at 40 lines.
How I verified it
All checks ran in the sandbox on base
8a580fcc2, origin/main at branch time. The tested head isf09f411fec9d85868c3c50b7e9c3acb43c3ab598; it adds the review round's commit on top ofcf6f0d40d. Since then,mainhas moved to67c724a54(#4206, #4207). Those two commits only addautomation.mdrows elsewhere, andgit merge-treewith them is clean.duplicateProject(3 failed, 19 passed). The controls passed.vitest list --changed origin/mainnames passed, 150/150:projects/routes.test.ts,lib/app-json-body.test.ts,app.json-body.test.tserror-reporting.test.ts,app.conditional-get.test.ts,app.health-stores.test.tsconversations/routes.test.ts,app/lib/backend/conversations.wire.test.tsapp.tsmounts them:appErrorHandler,requestId(),appJsonBody()on/api/app/*.{,{"name":"Copandname=Copyeach answer 400INVALID_JSONwith the request id. None of them calls the route'sgetProjectAuthContext, charges the rate limit, duplicates or reports anything.{}each duplicate under the default name.{"name":"Copy of P"}passes the name through.invalid body.{on create still answersINVALID_JSON..catch(() => ({}))back inside the helper fails 6 tests;authCtx) before the body read fails 3 tests, at the newgetProjectAuthContextassertion.oxlint --type-aware --type-checkon the changed TypeScript files is clean. A planted probe file was reported (TS2322 and an unused variable), which proves the run checks; the probe was then deleted.opengrep: 162 rules, 0 findings.bun run lint:manual: ok.git merge-tree --write-treeagainst the open fix(platform): preserve project-agent app save preconditions #4218, which also editsprojects/routes.tsandroutes.test.ts, is clean.Closes #3599