Repository navigation
fix(api): refuse bad post writes instead of answering 500 or returning the post - #1185
Merged
Merged
Conversation
…r leaking the post - PATCH /posts/:id needs post.view_private on every call and refuses a body with no updatable field (400), so a key that cannot read posts never gets one back - a repeated tag id is a 400 and an unknown or deleted tag a 404 on create and update, checked before anything is written - updatePost replaces tags and the post row in one transaction, so a failed tag insert never strips the post's tags - a deleted status is not found on create and update; a deleted post is not found on update - a proxy vote for an unknown voter is a 404, not a foreign-key 500
mortondev
force-pushed
the
fix/rest-post-writes
branch
from
November 20, 2026 11:55
d08f575 to
86014c6
Compare
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.
What this fixes
Six REST post writes that answered 500, wrote what they should have refused, or handed a post to a key that cannot read it. Each was found by the product e2e suite and has a quarantined test on #1167.
PATCH /api/v1/posts/:idwith{}(or only unknown fields) checked no permission or scope and returned the full post, so aread:chatkey could read any postpost.view_private(the answer carries the post) on top of each field's permission. A body with no updatable field is refused: 403 without the feedback write scope, otherwise 400PostTag not found; a repeated id is 400. Both are refused before the post is writtenStatus not foundPost not foundon update; nothing is written or announcedaddVoteOnBehalfchecks the voter in its CTE: 404User not found. Any existing principal, including another key's service principal, is still acceptedBehaviour changes worth a look
[a, a]and expect 400/404 with nothing written, so dedupe would keep them red.post.view_private. No system role has a post write permission without it; a custom role that does now gets 403 instead of the post.triage_post/ proxy votes and integration votes get them too.Quarantined e2e tests on #1167 this fixes
Lift after merge:
rest-posts.spec.ts: API-R-026 a PATCH with no recognised field is refused to a key that cannot read postsrest-posts.spec.ts: API-R-027 PATCH tags with an unknown tag id is refused and keeps the post's tagsrest-posts.spec.ts: API-R-012 an unknown or repeated tag id on create is refused without leaving a postrest-posts.spec.ts: API-R-013 a soft-deleted status is not found on create or updaterest-posts.spec.ts: API-R-028 a deleted post cannot be editedrest-votes.spec.ts: API-R-041 a proxy vote for an unknown voter is a not-found refusal, not a server error (the quarantined one; "API-R-041 proxy vote validation refusals" is already live)Tests
Each new test was run red against
origin/mainfirst, then green.post-service-writes.db.test.ts(new, real Postgres): unknown/repeated/deleted tags on create and update, nothing written when tags are refused alongside a title change, re-sending a deleted tag the post carries, deleted status on create and update, deleted post on update with no status event, unknown voter on proxy vote, service principal accepted as voter$postId.patch.test.ts(new): empty and unknown-field bodies refused to aread:chatkey with no post in the answer, read-only key refused, writer gets 400, a caller withoutpost.view_privaterefused, field permission still named first (R-025's messages unchanged), happy pathpost-service.test.ts: tag replacement goes through the transaction handle, never the bare dbpost-service,post.service-mentions,post-voting)