Skip to content

fix(id-web): rate-limit POST /api/identity/register per source (#1766) - #10674

Merged
dezren39 merged 1 commit into
mainfrom
queue/17434-1766-register-ratelimit
Nov 16, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/17434-1766-register-ratelimit

Conversation

@dezren39

@dezren39 dezren39 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements the #1766 remainder (triage task 11963, 2026-11-16): rate-limit POST /api/identity/register in id-web. The admission cap (#4143) already bounds how many identities can exist; the register handler itself was unthrottled, so a caller on a non-loopback bind could burn request-rate CPU/IO and cap-squat slots with junk registrations.

Changes

  • RegisterRateLimiter (id-web/src/lib.rs), following the SaveRateLimiter pattern: a per-source sliding-window limiter (default 10 successful registrations per source per 60s), with the id(web): SaveRateLimiter's per-file map grows without bound — entries expire after the 5s cooldown but are never evicted #1713 sweep discipline — entries are dropped once they can no longer refuse, so the map holds only sources active in the current window. Only successful registrations are counted; a refusal at the admission cap does not consume budget.
  • Handler (id-web/src/routes.rs): the source key is the peer IP from the listener's connect-info. Forwarded headers are never consulted — on the direct listener they are client-spoofable (the security.rs doctrine). Over-limit returns the structured refusal used by the save limiter (id(comms): per-peer frame/byte accounting + structured rate-limit refusal (P0 of #2032) #2244): 429 with a Retry-After header and body {"error": "registration_rate_limited", "reason": "rate_limited", "retry_after_ms": …}.
  • Listener wiring (id-cli/src/commands/serve.rs): the web router is now served with into_make_service_with_connect_info::<SocketAddr>() so connect-info exists in production. The program router served by publication listeners carries no identity routes, so it needs no change.
  • No identity deletion/expiry is added — that scope was retired by the 2026-11-16 ledger answer on lifecycle-retention-1766.

Tests

  • Limiter unit tests: under-limit allowed / over-limit refused with a sane remaining time, per-source independence, window expiry re-allows, ZERO window disables (the same off switch the save tests use).
  • Handler test: with a limit of 2, the first two registrations return 200, the third returns the structured 429 with Retry-After, and GET /api/identity/me for an already-registered identity still returns 200 (the limit is on registration only).
  • Targeted run: cargo test -p id-web --lib register from pkgs/id — see the PR checks/comments for the result line.

Queue task 17434, lane code-b. Resumed from an earlier session's checkpoint; its worktree was verified clean with no landed implementation before this change was written.

Closes #1766


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 16, 2026 10:12
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8bc39c25-8036-4c89-9a25-a854b34f6dbc
Commits

Reviewing files that changed from the base of the PR and between 948be51 and 4d60b19.

Files selected for processing: 3

  • pkgs/id/crates/id-cli/src/commands/serve.rs
  • pkgs/id/crates/id-web/src/lib.rs
  • pkgs/id/crates/id-web/src/routes.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-16T10:12:17.722059Z
We couldn’t complete this review. Comment @codex review to try again.
4d60b19 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@dezren39
dezren39 merged commit 72fff56 into main Nov 16, 2026
1 check passed
@dezren39
dezren39 deleted the queue/17434-1766-register-ratelimit branch November 16, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(web): registered identities are kept forever — no delete, expiry or cap at any layer, and the register handler is unthrottled

1 participant