Harden forward handler: SNS signature verification, rate limiting, atomic cap#11
Merged
Harden forward handler: SNS signature verification, rate limiting, atomic cap#11
Conversation
…omic cap 1. SNS signature verification (HIGH): Add sns-validator to cryptographically verify all incoming SNS messages before processing. Prevents forged notifications that could inject messages into any inbox or trigger arbitrary forwarding. 2. Subdomain forward rate limiting (MEDIUM): Cap at 200 forwards/hr per subdomain, logged to SendLog. Prevents catch-all abuse as an open relay for externally-originated spam. 3. Atomic message cap (LOW): Wrap count+create in a Prisma $transaction to prevent concurrent emails from racing past the 500 message limit. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Security audit found 3 vulnerabilities in the forward handler. All fixed.
1. SNS notification forgery (HIGH) — Forward handler only checked TopicArn, not cryptographic signature. An attacker who knew the ARN could forge notifications to inject messages into any inbox or trigger arbitrary forwards.
Fix: Added
sns-validatorpackage. All SNS messages are now cryptographically verified against Amazon's signing certificate before processing. Forged POSTs get 403.2. Catch-all open relay (MEDIUM) — A subdomain owner could set
catchAllForwardToto a victim's address, then external spam sent to*@attacker.x402email.comgets relayed through SES for free. Risks SES account suspension.Fix: Rate-limit subdomain forwards to 200/hr. Each forward logged to SendLog with a synthetic
[email protected]fromEmail for counting. Excess forwards are dropped with a log message.3. Message cap race condition (LOW) — TOCTOU between count check and message create. Concurrent SNS notifications could exceed the 500 message cap.
Fix: Wrapped count+create in a Prisma
$transactionfor atomicity.Test plan
[email protected]— should still be received (SNS signature valid)/api/inbox/forwardwith fake TopicArn gets 403🤖 Generated with Claude Code