Harden lookup counters #20

Merged
Taskuler-bot merged 1 commit from fix/harden-lookup-counters into main 2026-11-30 02:02:41 +00:00
Member

Follow-up to Taskuler Security's Re-review 2 (R2-2, R2-3, R2-5). Built on web #16 (the screening server code lives there; #18's branch doesn't include it). Merge after #14–#18. #14–#18 are unchanged. No deploy.

What changes (screening server only):

  • Budget order: the daily ipapi.is budget (900) is checked before anything is counted per network. Once it's spent, no new networks are recorded.
  • Bounded counters: at most 5,000 networks are tracked per UTC day (IPAPI_MAX_NETWORKS_PER_DAY). Past that, new networks get "unavailable".
  • Counter file:
    • Written in the background, at most once a second, with fsync of the file and its folder. It's also written when the service stops (SIGTERM), so a restart keeps the counts.
    • Local check: 20,000 different IPv6 /64s took about 0.3 s, and the file stays small (about 30 KB at the 900 cap, about 170 KB at the 5,000-network cap).
  • Fail closed:
    • If the file is corrupt, it's kept aside as .corrupt and lookups pause until 00:00 UTC. The same happens if the file disappears after the first start.
    • While saving fails, new lookups pause until a save works again.
    • To reset: delete daily-counters.json and daily-counters.json.init.
  • Client addresses:
    • Parsed with net.isIP. Every IPv4-mapped form and NAT64 (64:ff9b::/96) counts as its IPv4 address, for limits, lookups and the Tor list.
    • Anything unparsable gets 400 bad_client_ip.
  • Per-/48 limit: 120 requests per window per IPv6 /48 (SCREEN_RATE_LIMIT_48), on top of the per-/64 limit.

No user-facing text changes.

Checked:

  • npm test 173/173 on this branch, both tsc passes and the testnet build pass.
  • A local run of the service with stubbed providers: counts are written on SIGTERM and exit is 0.
  • The full order #14 → … → #20 merged locally passes too.
Follow-up to Taskuler Security's Re-review 2 (R2-2, R2-3, R2-5). **Built on web #16** (the screening server code lives there; #18's branch doesn't include it). Merge after #14–#18. #14–#18 are unchanged. No deploy. What changes (screening server only): - **Budget order:** the daily ipapi.is budget (900) is checked before anything is counted per network. Once it's spent, no new networks are recorded. - **Bounded counters:** at most 5,000 networks are tracked per UTC day (`IPAPI_MAX_NETWORKS_PER_DAY`). Past that, new networks get "unavailable". - **Counter file:** - Written in the background, at most once a second, with fsync of the file and its folder. It's also written when the service stops (SIGTERM), so a restart keeps the counts. - Local check: 20,000 different IPv6 /64s took about 0.3 s, and the file stays small (about 30 KB at the 900 cap, about 170 KB at the 5,000-network cap). - **Fail closed:** - If the file is corrupt, it's kept aside as `.corrupt` and lookups pause until 00:00 UTC. The same happens if the file disappears after the first start. - While saving fails, new lookups pause until a save works again. - To reset: delete `daily-counters.json` and `daily-counters.json.init`. - **Client addresses:** - Parsed with `net.isIP`. Every IPv4-mapped form and NAT64 (`64:ff9b::/96`) counts as its IPv4 address, for limits, lookups and the Tor list. - Anything unparsable gets 400 `bad_client_ip`. - **Per-/48 limit:** 120 requests per window per IPv6 /48 (`SCREEN_RATE_LIMIT_48`), on top of the per-/64 limit. No user-facing text changes. Checked: - `npm test` 173/173 on this branch, both `tsc` passes and the testnet build pass. - A local run of the service with stubbed providers: counts are written on SIGTERM and exit is 0. - The full order #14 → … → #20 merged locally passes too.
Global lookup budget is checked before per-network counting; per-network entries are capped per day;
the counters file is written asynchronously (debounced, fsync, flushed on SIGTERM); a corrupt or
missing file, or a failing save, pauses lookups (fail closed). Client addresses are parsed with
net.isIP (IPv4-mapped and NAT64 forms map to IPv4; junk is refused), plus a per-/48 rate limit.
george approved these changes 2026-11-30 01:56:35 +00:00
Taskuler-bot changed target branch from fix/screening-service-limits to main 2026-11-30 02:02:38 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
taskuler/web!20
No description provided.