Repository navigation
fix(api): keep 404 for an application you cannot access - #609
Merged
Merged
Conversation
Caught smoke-testing dev after the readClient change: cross-organisation
requests started returning 403 where they had returned 404.
The lookup now runs above RLS, so a real id is always found — which means
the "no org access" branch fires and a 403 tells a stranger that an
application exists and simply is not theirs. Before, RLS hid the row and
the route 404'd for the wrong reason.
The routes always intended 404 before 403; the comments in both files say
so. This makes that property hold on purpose rather than by accident, so a
caller still cannot distinguish "not yours" from "not a real id".
Applies to GET and PATCH /v1/employer/applications/{id} and the
per-application scheduling authorisation.
Contributor
Author
|
Deployed to dev ( The bogus-id and cross-org responses being identical is the property this PR restores: a caller cannot tell "not yours" from "not a real id". Built-in deploy smoke also passed 5/0/2 (the two skips are dev having no canonical web URL and no |
This was referenced Aug 12, 2026
thinkclay
added a commit
that referenced
this pull request
Aug 12, 2026
…called (#447) (#614) core.reviews and its five child tables have been in place since migration 099, and ReviewWizard drives a full multi-step flow against @scaffald/sdk. The router implemented four of the thirteen endpoints the SDK exposes, so every step of writing a review 404'd. Same shape as the profile epic: a good database, a built UI, and no wire between them. Added: GET /reviews/my-reviews reviews the caller has written GET /reviews/soft-skills/by-category the catalog grouped for the tabs GET /reviews/{id}/draft reopen a part-written review PATCH /reviews/{id}/draft whole-blob autosave PATCH /reviews/{id}/step wizard progress PATCH /reviews/{id}/skill-ratings technical scores PATCH /reviews/{id}/category-rating one category at a time PATCH /reviews/{id}/soft-skill-votes strengths and improvements PATCH /reviews/{id}/comment body + public visibility GET /reviews/analytics aggregates for a subject Ownership is the review system's whole integrity, so it lives in one helper rather than being retyped per handler: loadOwnReview filters on id AND author_user_id, and a miss is a 404 rather than a 403 — the convention #608/#609 settled on, because "exists but not yours" leaks that it exists. Verified against a live stack: another user's draft is 404 on both read and write. Mutations additionally require the review to still be a draft. A submitted review is a published statement about someone; letting the author keep editing would change what a reader already saw. Three things the live run caught that static reading would not have: - **Two endpoints 500'd on "permission denied".** `authenticated` had no DELETE grant on review_skill_ratings or review_soft_skill_votes, and both endpoints replace their set rather than merging — the reviewer sends the full list, so a removed skill has to actually disappear. Migration 346 adds the grants, plus a DELETE policy on review_skill_ratings mirroring its insert predicate (review_soft_skill_votes already had an author-scoped ALL policy). Same class as #481: RLS and a policy exist, the GRANT that makes the policy reachable does not, and it surfaces as a server error rather than a permission one. - **Analytics resolved skill names from the wrong table.** I joined data.masterformat; review_skill_ratings.skill_id has a foreign key to core.skills. It returned blank names until a live call showed it. - **POST /{id}/submit was destroying the review.** It set `metadata: { status: "submitted" }` — a whole-object write over the jsonb column holding the draft body, the wizard's step progress and the is_public flag the comment step had just saved. Everything the reviewer filled in was dropped at the moment they submitted it. Now merged, and it checks ownership like the rest. KNOWN_GAPS drops 83 -> 73, and the contract suite is added to test:api:rest:suite — it has never run in CI, which is the same gap #604 fixed for __tests__/lib. Co-authored-by: Claude Opus 5 <[email protected]>
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.
Caught smoke-testing dev after #608. Cross-organisation requests started returning 403 where they had returned 404.
Why it changed
#608 moved the authorisation lookup above RLS, so a real application id is now always found. That makes the "no org access" branch fire — and a 403 there tells a stranger that an application exists and simply is not theirs. Previously RLS hid the row and the route 404'd, for the wrong reason.
Both files already carried the comment "404 before 403 on a missing row, so a stranger cannot probe which application ids exist." That property was holding by accident. This makes it hold on purpose.
Measured on dev
GET /{id}GET /{id}Applies to
GETandPATCH /v1/employer/applications/{id}and the per-application scheduling authorisation.deno lintanddeno fmt --checkclean. Dev smoke to follow after deploy.