Repository navigation
fix(service-bridge): per-principal rate buckets with a global backstop (wiki-v2 issue 780) - #83
Merged
Merged
Conversation
docmost#780) The bridge limiter was one fixed 60 s window per scope, shared by every platform caller, so one principal could lock all /v1 page routes and imports out until the window reset. - Token buckets (continuous refill, all-or-nothing debit, pruned) replace the fixed window. - The platform names the acting principal in x-ccc-rate-principal (a rate key only, parsed after the secret check). Attributed calls debit their own bucket plus a per-scope global backstop; unattributed background calls keep their own bucket and never touch the global one. - A refusal is 429 {code: rate_limited} with Retry-After; the bad-secret bucket answers service_auth_throttled. SERVICE_BRIDGE_RATE_LIMITED logs scope and bucket kind, never the principal. - service-bridge.openapi.json 1.15.0: RatePrincipal header, RateLimitedError, Retry-After on every 429. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vwm9j5xBxNaA7WUcUdQroX
…incipal (wiki-v2 issue 780) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vwm9j5xBxNaA7WUcUdQroX
…incipal (wiki-v2 issue 780) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vwm9j5xBxNaA7WUcUdQroX
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.
What
Per-principal rate buckets for the service bridge, with a global backstop per scope. This fixes https://github.com/cccvu/wiki-v2/issues/780. It is paired with the super PR https://github.com/cccvu/wiki-v2/pull/787.
service-rate-limit.ts: token buckets replace the fixed 60 s window. Refill is continuous. A debit across several keys is all-or-nothing, so a refused call drains nothing. Full buckets are pruned when a call comes in; there are no timers.service-auth.guard.ts: after the secret and scope checks, the guard readsx-ccc-rate-principal(user:<uuid>orservice:<uuid>). It is only a rate key, never identity. A malformed value gets a fixed400that never echoes the value.scope:principalbucket and that scope's global backstop.pages:readandpages:authz:read6000/60000/6000,pages:import:read120/1200/120, every other scope 1200/6000/600. Bad-secret calls share one anon bucket of 600.429 {code: "rate_limited"}+Retry-After. The anon bucket answersservice_auth_throttledinstead, so a wrong secret is never reported as the caller's own throttle. The log line isSERVICE_BRIDGE_RATE_LIMITED scope=… bucket=principal|global|unattributed|anon, and it never includes the principal.service-bridge.openapi.json1.15.0 adds theRatePrincipalheader parameter andRateLimitedError, and putsRetry-Afteron every 429. The README is updated to match.Why
The old limiter was one fixed window per scope, shared by every platform caller. A single principal could use up
pages:readorpages:import:readand lock every other caller out of/v1page routes and imports until the window reset.Scope
Only
apps/server/src/service-bridge/**anddocs/integrations/authorization/**change, both CCC-owned. There is no upstream seam, andcheck-upstream-boundary.shpasses.Tests
FORK_SPEC_ROOTSlane (authz, service-bridge, editor-compat, prosemirror, import): 216 suites, 3516 passed. The pg specs skipped themselves because no Postgres was running.src/service-bridgeagain: 44 suites, 508 passed.tsc --noEmitand the super repo'sdocmost-server-typecheck.mjs(forward and reversed) are clean.pages:readandpages:import:read:Merge this first, with a merge commit. The super PR (https://github.com/cccvu/wiki-v2/pull/787) then re-pins its gitlink to the merge SHA.
🤖 Generated with Claude Code