fix(rest): refuse unknown query parameters on GET /approvals/requests instead of returning every request - #7607
Conversation
…#7527) `?assignedToMe=true` answered 200 with every request the caller could see — the handler read the keys it knew and dropped the rest, so a caller who believed they asked for "the requests assigned to me" got the unfiltered list and could not tell, because an unfiltered result is shaped exactly like a genuinely broad match. The route now declares a closed parameter set, measured from the handler's own reads (five filters, `q`, the paging pair, and the snake_case aliases it honours), and refuses anything outside it with a located 400 carrying the ADR-0112 nested envelope — the same position and code the repeated-parameter refusal on this same handler already answers with. The message names the unrecognised parameters and lists the supported ones. `assignedToMe` is refused rather than implemented: the Console already asks this question as `approverId=<id>,role:user`, so a second spelling would be surface with no pull behind it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015fkdTyGmMD5s8ZtEifvuGy
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📓 Docs Drift CheckThis PR changes 1 package(s): 9 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
⛔ 3 release-owned page(s) also reference the affected code. These are read-only:
|
Fixes #7527
The defect
GET /api/v1/approvals/requests?assignedToMe=trueanswered 200 with every request the caller could see. The handler reads the keys it knows off the query string and ignores the remainder, so a caller who believes they asked for "the requests assigned to me" is handed the unfiltered list — and cannot tell, because an unfiltered result is shaped exactly like a genuinely broad match. No status, header or field distinguishes "your filter matched everything" from "your filter was thrown away".Same anti-pattern as #7463's defect 2 (tracked as #7534), pointed the other way: there an unrecognised key silently NARROWS to zero, here an unrecognised parameter silently WIDENS to everything.
The fix — refuse, not alias
The route declares a closed parameter set and refuses anything outside it with a located
400carrying the ADR-0112 nested envelope,{ error: { code: 'VALIDATION_ERROR', message } }— the same position and code the repeated-parameter refusal (#6877) on this same handler already answers with, so one route never speaks two dialects for two flavours of "this request is malformed". The message names the parameters that were not understood and lists every one that is supported, so a caller can fix the request from the response alone.assignedToMeis refused rather than implemented, per the #5714 / #5931 / #7463 family norm. The capability it reaches for already exists and is already reachable — the Console asks exactly this question asapproverId=…,role:user, which theapproverIdmulti-identity arm was built for. A second spelling for a question that already has one is surface with no pull behind it and has to be carried forever; refusing costs one error path and makes every future typo self-reporting.Premise verified before implementing: nothing consumes
assignedToMe.grepover the whole worktree — all packages, all ofexamples/**, thepackages/consoleprebuilt-SPA package — returns zero hits in any file type. The client SDK'sapprovals.listRequestssends onlyobject/recordId/status/approverId/submitterId(packages/client/src/index.ts), a strict subset of the closed set.The closed set was MEASURED, not guessed
APPROVAL_REQUEST_LIST_PARAMSis read off the handler's own reads, and is exported so the pin tests assert against it rather than a hand-copied second list that can drift:object,recordId,status,approverId,submitterIdqlimit,offsetrecord_id,approver_id,submitter_idPaging is inside the set on purpose — a whitelist built from the filters alone would have traded a silent-widening bug for a loud paging outage. Auth is header-based (
computeExecCtxreads no query key) and the Hono adapter copiessearchParamsverbatim with no synthetic keys, so nothing else legitimately arrives here.Where the code actually lives — a falsified dispatch assumption
The dispatch expected the route in
packages/plugins/plugin-approvals/src/, and the card said the same ("Not located in this run"). It is not there.GET /api/v1/approvals/requestsis registered byregisterApprovalsEndpointsinpackages/rest/src/rest-server.ts(approx. line 9200);plugin-approvalssupplies the service behind it (listRequests) and declares the per-record action targets, but owns no route registration. The fix is therefore inpackages/rest, andplugin-approvalsis unmodified. Its suite is run below as a regression check only.Tests
New
packages/rest/src/rest-server-approvals-unknown-filter.test.ts— 13 cases. These handlers send, they do not throw, and on the unfixed code the answer was an ordinary200, so atoThrow-shaped assertion would be worthless and a status-only one is half a test: the defect is thatlistRequestsran and its rows were returned. Each refusal case asserts the ADR-0112 pair (statusAND nestedbody.error.code), the located message, and that the service was never asked.assignedToMe; the located message; four other plausible misspellings (assigned_to_me,assignee,mine,approver,ApproverId) failing identically, since the bug is the class and not the one name; multiple unknowns named in deterministic sorted order; unknown-parameter refusal outranking the repeated-parameter one.approverId=u_42,role:userstill narrowing (asserted on the argument handed to the service, not the status); the unparameterised call still returning the full list; paging reaching the paged branch (totalpresent); the snake_case aliases; and every name in the exported set accepted.nullquery, all-recognised, singular vs plural phrasing.Reverse verification — direction predicted first
Prediction: removing the gate turns the §1 cases red while §2 and §3 stay green (they do not depend on it). Measured, with the fix taken out via
Editand restored the same way:The red output reproduces the reported defect verbatim — a
200carrying both rows — rather than failing generically, which is what makes it a pin on this bug and not on "something changed".Suites and gates
pnpm --filter '@objectstack/rest^...' build(build closure first)pnpm --filter @objectstack/rest testpnpm --filter @objectstack/rest typechecktsc --noEmit, no output)pnpm --filter @objectstack/plugin-approvals testpnpm check:docs-audit-scopenode scripts/check-nul-bytes.mjsThe
plugin-approvalssuite first failed 5 files at collection withFailed to resolve entry for package "@objectstack/service-automation"— the unbuilt-dependency trap, not this change. Green at the full 21/458 baseline afterpnpm --filter '@objectstack/plugin-approvals^...' build.Scope
Deliberately not here: the card's wider suggestion to reject unknown query parameters across all endpoints. That is a cross-lane REST-ingress policy decision with a real breaking-change surface, not an approvals bug — filed for triage as #7606 (searched first; no duplicate). The helper it would reuse is introduced here and proven on one route.
Generated by Claude Code