Notifications: explicit mark-read, drop side effect from GET - #226
Merged
Conversation
GET /notifications/ marked all notifications read as a side effect, so a
GET mutated state — reading the list cleared the unread badge, and any
cache/prefetch/retry did too, with no way to just view without clearing.
Make the read pure and add explicit write endpoints:
- GET /notifications/ list, read-only
- POST /notifications/read/ mark all read -> { markedRead }
- POST /notifications/{notificationId}/read/ mark one read -> 204 (404 if not
the caller's / missing)
Security: remove the unused, un-scoped find_account_notification_by_id
(latent IDOR) and add mark_account_notification_as_read(account_id, id)
that scopes by account_id in the WHERE clause, so another account's id
updates no rows and returns 404 without revealing whether it exists.
Behavior change: clients that relied on "GET clears unread" must now call
POST /notifications/read/. No migration.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
GET /notifications/marked all notifications as read as a side effect (list_notificationscalledmark_all_...as_readafter listing). AGETmust be safe/idempotent — this one mutated state:GET /unread/count raced againstGET /notifications/zeroing it.Change
Make the list a pure read and add explicit write endpoints:
/notifications//notifications/unread/{ unreadCount }(unchanged)/notifications/read/{ markedRead: n }/notifications/{notificationId}/read/204(404if not the caller's / missing)Security
find_account_notification_by_id(looked up by id only — a latent IDOR if ever used for per-item writes).mark_account_notification_as_read(account_id, id)scopes byaccount_idin theWHEREclause: another account's id (or a missing one) updates 0 rows →404, with no read-then-write race and no way to probe whether an id exists.Behavior change
Clients that relied on "GET clears unread" must now call
POST /notifications/read/explicitly. No DB migration (all columns/queries existed; added one query).Testing
Full gate green (check / fmt / clippy / doc / test).
🤖 Generated with Claude Code