Add hosted captun.sh rate limits#17
Conversation
commit: |
…s' into mmkal/26/05/23/hosted-rate-limits
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 256fd37. Configure here.
| limit: check.limit, | ||
| windowSeconds: config.windowSeconds, | ||
| }); | ||
| if (!result.ok) return hostedRateLimitedResponse(result); |
There was a problem hiding this comment.
Split checks consume quota early
Medium Severity
For hosted HTTP requests, rate limiting runs per-IP then per-tunnel in separate HostedRateLimiter calls, and each successful check increments its bucket before the next check. If the later per-tunnel check returns 429, the per-IP counter is already increased even though the request never passed all limits, so clients can hit IP limits faster than the configured allowance.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 256fd37. Configure here.
|
Superseded by #20, which now uses this branch history as part of one combined hosted safety review. |


Summary
Adds the first hosted-service abuse guardrail for
captun.sh: a hosted-only Durable Object rate limiter for anonymous public tunnels.Behavior:
429responses withRetry-After,cache-control: no-store, andx-captun-rate-limitcaptun.shif the limiter binding is missing, unless explicitly disabled withHOSTED_RATE_LIMIT_DISABLED=1cf-connecting-ipfor hosted client identity; spoofable forwarded-IP headers collapse tounknownThe first public defaults are intentionally coarse, not billing-grade quota accounting:
Follow-up left out intentionally
Ownership tokens, active tunnel caps, byte/stream limits, Cloudflare-native edge rate limiting bindings, and observability are listed in the task file as follow-up work.
Verification
pnpm run checkpnpm testpnpm run buildCAPTUN_PUBLIC_E2E=1 pnpm vitest run test/public-hosted.test.tsNote
Medium Risk
Changes hosted
captun.shthrottling behavior and Durable Object keying, which can impact availability (503/429) and effectiveness of abuse protection if misconfigured. Scoped to hosted mode but touches request admission paths and rate-limit enforcement.Overview
Refactors hosted
captun.shrate limiting to scale and harden defaults. TheHostedRateLimiterDurable Object is simplified to track a single fixed-window bucket, and rate limiting is now performed by multiple DO instances named via a hash of each bucket key (per-IP / per-tunnel) instead of a single global DO with an in-memory map.Tightens safety and trust boundaries. Hosted mode now fails closed with a
503when theHostedRateLimiterbinding is missing (unlessHOSTED_RATE_LIMIT_DISABLED=1is explicitly set), and client IP detection for rate limiting is restricted tocf-connecting-ip(no longer trusting spoofable forwarded-IP headers). Tests and the hosted rate-limit task notes are updated to cover/describe these behaviors.Reviewed by Cursor Bugbot for commit 256fd37. Bugbot is set up for automated code reviews on this repo. Configure here.