fix: rate-limit and coarsen /merchants/available discovery (G1) - #362
Merged
Conversation
/merchants/available was public, unauthenticated, with no rate limit, and returned exact lat/lng — letting anyone scrape the full census of merchant locations. Add a 30 req/min per-IP rate limiter and round the publicly returned latitude/longitude to 3 decimals (~110m); distance_km still uses the exact stored coordinates via the existing SQL Haversine. Exact coordinates remain available to a counterparty only inside an accepted trade. Note: micopay/backend/package.json also carries pre-existing unrelated script additions (test:trade-auth, test:refund, test:challenge) from outside this change set — verified harmless/compatible, included because they share the same file/hunk as the new test:discovery script.
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
Extracts a third independent, already-verified fix from the stalled #344 (62 files, CONFLICTING, open since Jul 27):
GET /merchants/availablehad no rate limit and returned exact merchant coordinates to any unauthenticated caller (see thestays unauthenticatednote atroutes/merchants.ts:59before this change)./merchants/available(429 +Retry-Afteronce exceeded).Cherry-picked from
db7455bonto currentorigin/mainin an isolated worktree. One conflict inmicopay/backend/package.json: bothorigin/mainand this commit had appended newscriptsentries aftertest:security(mainaddedtest:sign-requests/issue-device-key; this commit addedtest:trade-auth/test:refund/test:challenge/test:discovery). Resolved by keeping all six script entries from both sides; thedependenciesblock merged cleanly with no conflict. Rannpm installafterward to confirm the lockfile needed no changes.Test plan
npm ci && npm run build-> passes with no errorsnpm run test:discovery(in-memory DB, mocked Stellar) -> all 4 tests pass, including "30 requests from the same IP within the window are allowed" and "request past max is rejected with 429 and Retry-After"