fix(newsletter): rate limit signups and stop resending welcome email - #68
Merged
royalpinto007 merged 1 commit intoAug 7, 2026
Merged
Conversation
POST /api/newsletter had no rate limit, unlike every other public write route in the app, making it the cheapest endpoint to abuse for enqueueing unlimited welcome emails to arbitrary addresses. Apply consumeSharedRateLimit per IP, same as teams/waitlist. Also guard the welcome email so a repeat signup for an already-active subscriber doesn't re-send it — a second amplification path the rate limit alone wouldn't close.
|
Merged, @waterlemonnn. Thank you for taking the time. Contributions like this are what keep agentpostmortem moving. A star on the repo would mean a lot if this project is useful to you. Happy to see more from you whenever you have the time. |
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.
Closes #60.
POST /api/newsletterwas the one public write route withoutconsumeSharedRateLimit— unlikeposts,comments,vote,upload/presign, andteams/waitlist. That made it the cheapest endpoint to abuse: a script could enqueue unlimited welcome emails to arbitrary addresses (a third-party email-bomb primitive on our domain), and every request costs a Resend send plus a Supabase write.consumeSharedRateLimitkeyed by IP, same pattern asteams/waitlist/route.ts(3 req / hour — tighter than waitlist's 5/hour since a real signup only happens once).status: activeno longer re-sends the welcome email. It still sends on a genuinely new signup, and on reactivation (existing row moving from a non-active status back to active).Verify
New tests cover: new-subscriber welcome send, no resend for an already-active subscriber, resend on reactivation, and 429 short-circuits before any DB/email call.