Repository navigation
fix(api): rate limit the billed places and weather tile routes - #544
Open
silvertakana wants to merge 1 commit into
Open
silvertakana wants to merge 1 commit into
silvertakana wants to merge 1 commit into
Conversation
Both routes hold billed upstream keys server-side and had no throttle, and place search is publicly reachable, so one anonymous client could run up the bill or exhaust the quota. - placesLimiter: 30 req/min/IP for places/search and places/details - weatherTileLimiter: 240 req/min/IP for the raster tile route - the check runs first in GET, before parsing or any upstream call, and reuses the existing 429 shape - add limiter unit tests with literal budgets
Contributor
|
Left for a person rather than auto-merged: not a Dependabot pull request. Patch and minor updates merge themselves once every check has completed green; this one is listed in the weekly dependency digest. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Why
Two routes hold billed third-party keys server-side and had no throttle at all:
/api/places/searchand/api/places/detailsproxy Google Places (billed per request), and search is publicly reachable — so an anonymous client could run up the bill with no limit in the way./api/weather/tile/...proxies billed raster tiles, and one viewport pulls dozens of tiles per pan or zoom.What
Two limiters added to
src/lib/rateLimiters.ts, following the existing pattern:placesLimiterplaces/search,places/detailsweatherTileLimiterweather/tile/[z]/[x]/[y]Each route runs the check as its first statement, before parsing and before any upstream call, and reuses the 429 shape the already-limited routes serve —
Retry-Afterplus{"error":"Too many requests"}— rather than inventing a second one.The weather budget is deliberately generous: a map viewport pulls many tiles at once, and 240/min still bounds a single client to well under the upstream per-minute allowance.
Tests
New
src/lib/rateLimiters.test.ts(9 tests): under-limit passes, over-limit is refused, the counter is per-IP, and the 429 wire shape is asserted. Expected budgets are literals, so a changed limit cannot keep the suite green.src/lib/as a whole: 60 files, 767 tests pass.tsc --noEmitandeslintclean on every touched file.expected 'allowed=1 blocked=30' to be 'allowed=30 blocked=1'), then restored and re-run green.Independent of the plugin-data routing work in flight elsewhere.