Skip to content

fix(api): keep 404 for an application you cannot access - #609

Merged
thinkclay merged 1 commit into
mainfrom
claude/deploy3
Aug 12, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/deploy3

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

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

request before #608 after #608 now
org admin GET /{id} 404 (wrong) 200 200
cross-org GET /{id} 404 403 (leaks) 404
cross-org scheduling 404 403 (leaks) 404
unauthenticated 401 401 401

Applies to GET and PATCH /v1/employer/applications/{id} and the per-application scheduling authorisation.

deno lint and deno fmt --check clean. Dev smoke to follow after deploy.

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.
@thinkclay
thinkclay merged commit a2066ad into main Aug 12, 2026
6 of 12 checks passed
@thinkclay
thinkclay deleted the claude/deploy3 branch August 12, 2026 08:34
@thinkclay

Copy link
Copy Markdown
Contributor Author

Deployed to dev (a2066ad89) and smoke-tested. All green:

owner     list                  total=8
admin     list                  total=8      <- was 0 before #607
admin     GET /{id}             200          <- was 404 before #608
admin     scheduling per-app    200
admin     eeo-report            200

cross-org GET /{id}             404   (not 403 — no existence leak)
cross-org scheduling            404
bogus id                        404          <- indistinguishable, which is the point
unauthenticated                 401
wizard    list (own org only)   total=5

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 SMOKE_USER_* credentials in .env.dev).

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant