Repository navigation
feat(scan): rate limit live scans per IP and per user - #135
Open
DevOlabode wants to merge 2 commits into
Open
DevOlabode wants to merge 2 commits into
DevOlabode wants to merge 2 commits into
Conversation
- Anonymous scans are limited per IP (IPv6 grouped by subnet); signed-in scans are limited per user so shared IPs don't share a budget - Blocked requests get 429 RATE_LIMITED with Retry-After and never launch Chromium - Guard that express-rate-limit keeps a CommonJS entry for Vercel
GET /api/scan-results also runs a live Chromium scan and is what the results page uses on refresh or a shared link, so it bypassed the limit. Both routes now share one limiter, so a scan costs one unit either way.
This branch has not been deployed
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.
Adds rate limiting to the live-scan routes,
POST /api/scanandGET /api/scan-results. Every scan launches a headless Chromium, so without a limit, request volume was a cost and abuse risk.GET /api/scan-resultsalso runs a full scan. The results page uses it on refresh or a shared link, so left unlimited it would bypass the limit. A normal scan from the landing page counts once.429with codeRATE_LIMITEDand aRetry-Afterheader, and Chromium never launches. The frontend already shows the server'serrortext.express-rate-limit, built per app inapp.js(the composition root) and passed down to the scan router.dependencies.test.jsnow checks that it keeps a CommonJS entry, since Vercel can'trequire()ESM-only packages.Known limit: counts live in memory, so each warm Vercel instance counts on its own and a cold start resets them. This is marked in the code with the upgrade path: a shared store via the library's
storeoption.The limits are constants at the top of
backend/middleware/scanRateLimit.js, so they're easy to tune.Closes #128