fix(adsbdb): rate-limit /api/adsbdb and cap its enrichment caches

Both keys this route accepts come from the caller — a callsign is 2-8 of
[A-Z0-9], a hex is six of [0-9a-f] — and every distinct key that reached
upstream was cached, 404s included, with nothing ever removing one. A caller
walking the keyspace could therefore drive unlimited live requests at the free
community API and grow `.gev-cache/adsbdb.json` without end.

Admit 360 requests/minute per client address, global backstop 3x, refusing the
rest with 429 and `Retry-After` before any cache, disk or upstream work. The
browser cannot exceed 300/min by construction: ENRICH_DISPATCH_GAP_MS is
200 ms, so the enrichment queue drips at most five lookups a second.

Hold each store to 20,000 entries, dropping least-recently-written first, and
discard entries past the existing 24-hour TTL when the file is read back. A
cache file above 16 MB is skipped rather than parsed. Sized from a real
session's own file: 397 aircraft entries (~100 B) and 3 route entries
(~231 B), so the ceiling is about fifty times an ordinary working set and
bounds the file at roughly 7 MB.

The two stores become Maps: `size` is O(1), so the ceiling can be enforced on
every write, and iteration is true insertion order — an all-digit callsign
like "1234" sorts ahead of everything else as an object key. The on-disk JSON
shape is unchanged.

Refs #261
This commit is contained in:
daikaginza committed 2026-09-27 22:23:55 +07:00
1 parent b210ab0fe4
commit 03814d8c47
7 files changed
+362 -18

No files matched your search

+11
View File
@@ -1,5 +1,16 @@
# Changelog
- Bound the adsbdb enrichment proxy. `/api/adsbdb` had no request limit and no
cache eviction, so a caller cycling through the callsign or hex keyspace
could drive unlimited live requests at the free community API and grow
`.gev-cache/adsbdb.json` without end — every distinct key, 404s included, was
remembered forever. The route now admits 360 requests/minute per client
address (the browser's own drip cannot exceed 300), refusing the rest with
429 and `Retry-After` before any cache, disk or upstream work. Each cache
holds at most 20,000 entries, dropping the least-recently-written first, and
entries past the existing 24-hour TTL are discarded when the file is read
back. Cached answers and response shapes are unchanged.
- CCTV cameras whose bearing is a guess now say so. Packs mark bearings derived
from a hash of the camera id as `headingConfidence: 'low'`, but nothing read the
flag, so roughly 70% of a default catalog rendered like surveyed facings. The HUD