fix: add auth and validation boundary to notification/preference APIs - #1876
Closed
Shindy-Ship wants to merge 32 commits into
Closed
Shindy-Ship wants to merge 32 commits into
Shindy-Ship wants to merge 32 commits into
Conversation
|
@Shindy-Ship Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@Shindy-Ship is attempting to deploy a commit to the 1nonly's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
@Commitlabs-Org Hi! This PR is open and ready for review — happy to address any feedback. Thanks! |
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.
Overview
This PR enforces a clear authorization and validation boundary for the notification API and user preferences API, addressing the production-quality risk area of notification/preference consistency across sessions and tabs. It defines explicit state, data, authorization, and failure invariants; validates route parameters, wallet identity, network, numeric values, and server responses at the boundary; and ensures ownership and authorization assumptions are checked server-side rather than inferred from client state. Replay, tampering, wrong-network, disconnected-wallet, and malformed-response scenarios are covered with focused automated tests. Design tradeoff: validation and auth logic is centralized in
src/lib/validation.tsandsrc/lib/auth.tsso both route handlers stay thin and consistent. Remaining limitation: anti-replay state is currently per-instance; a shared store would be needed for multi-instance deployments.Related Issue
Refs #568
Changes
🔐 Authorization & Validation Boundary
[ADD]
src/lib/validation.ts[ADD]
src/lib/auth.ts[MODIFY]
src/app/api/notifications/route.ts[MODIFY]
src/app/api/user/preferences/route.ts[ADD]
src/app/api/notifications/route.test.ts[ADD]
src/app/api/user/preferences/route.test.ts[ADD]
src/lib/validation.test.ts[ADD]
src/lib/auth.test.tsVerification Results
validation.tsand route handlersauth.tsverifies signed session proofCloses #1790