Skip to content

feat(proxy): rate limiter + insecure-bind warning#16

Merged
keirsalterego merged 1 commit into
mainfrom
fix/rate-limit-and-bind-warning
May 25, 2026
Merged

feat(proxy): rate limiter + insecure-bind warning#16
keirsalterego merged 1 commit into
mainfrom
fix/rate-limit-and-bind-warning

Conversation

@keirsalterego

Copy link
Copy Markdown
Contributor
  • Global fixed-window rate limiter (100 req/s) as axum middleware to shed unauthenticated floods before HMAC verification. Logic extracted to rate_check() + 2 unit tests.
  • Warn on non-loopback plain-HTTP bind unless ALLOW_INSECURE=true (non-breaking).

cargo test 19 passed (+2), cargo fmt --check + clippy -D warnings clean. No CI configured on this repo — verified locally. (Audit-chain Python/Rust parity is deferred — it touches the tamper-evidence chain and needs shared test vectors.)

🤖 Generated with Claude Code

- Add a global fixed-window rate limiter (100 req/s) as axum middleware to shed
  unauthenticated request floods before they reach HMAC verification (a CPU-DoS
  vector even though forgery is infeasible). Decision logic is extracted to a
  pure rate_check() with unit tests.
- Warn loudly when binding plain HTTP to a non-loopback address without
  ALLOW_INSECURE=true (containment traffic would be cleartext with no proxy in
  front). Non-breaking: it warns, it does not refuse, so the supported
  plain-HTTP-behind-reverse-proxy deployment still works.
Copilot AI review requested due to automatic review settings May 25, 2026 04:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a global request-rate shedding mechanism and improves operator visibility for potentially unsafe plain-HTTP deployments.

Changes:

  • Introduces a global fixed-window rate limiter (100 req/s) implemented as Axum middleware, with logic extracted into rate_check() plus unit tests.
  • Adds a warning when binding plain HTTP to a non-loopback address unless ALLOW_INSECURE=true.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.rs
Comment on lines +99 to +102
/// Fixed-window global rate-limit counter: (window start, count in
/// window). Shared across handlers to shed request floods. See
/// `rate_limit` / `rate_check`.
rate: Arc<Mutex<(Instant, u32)>>,
Comment thread src/main.rs
Comment on lines 500 to +504
let app = Router::new()
.route("/health", get(health))
.route("/execute", post(execute))
.route("/audit/export", get(export_audit))
.layer(middleware::from_fn_with_state(state.clone(), rate_limit))
Comment thread src/main.rs
Comment on lines +539 to +542
let is_loopback = bind_addr
.parse::<std::net::SocketAddr>()
.map(|a| a.ip().is_loopback())
.unwrap_or(false);
@keirsalterego keirsalterego merged commit a607192 into main May 25, 2026
1 check passed
@keirsalterego keirsalterego deleted the fix/rate-limit-and-bind-warning branch May 25, 2026 04:15
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.

2 participants