fix(aver-scope-shim): stream proxy bodies, harden scope injection#5
fix(aver-scope-shim): stream proxy bodies, harden scope injection#55queezer wants to merge 1 commit into
Conversation
- Stream request/response bodies end-to-end instead of store-and-forward: SSE (MCP streamable HTTP) responses now reach clients incrementally and shim memory stays bounded. Request bodies are capped at 16 MiB (413); response bodies are never capped. - Add upstream deadline (30 s to response headers) plus 10 s connect timeout so an upstream hang no longer hangs the shim. - Filter empty/whitespace --scope values like the env-var path, so an empty X-Aver-Scope header is never injected. - Validate the scope as a legal HTTP header value once at startup instead of failing per-request with 502. - Collapse a duplicated /mcp path prefix so a shim URL + /mcp is not forwarded to /mcp/mcp. The proxy moves from main.rs into a testable aver_scope_shim::proxy module; main.rs is CLI/startup wiring only. Adds HTTP integration tests against an in-process upstream: header injection, no-scope passthrough (client header stripped), incremental SSE streaming, 413 on known-length and chunked uploads over the cap, upstream-hang 504, and /mcp collapsing.
|
Warning Review limit reached
Next review available in: 36 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Fixes all findings from the aver-scope-shim code review. The proxy moves from
main.rsinto a testableaver_scope_shim::proxylibrary module;main.rsis now CLI parsing + startup wiring only.Findings → fixes
main.rsbuffered request viato_bytes(body, usize::MAX)and response via.bytes().await): bodies now stream in both directions (reqwest::Body::wrap_streamout,axum::body::Body::from_streamin). SSE /text/event-streamresponses reach the client incrementally; shim memory stays bounded. Request bodies are hard-capped at 16 MiB → 413 (up-front viaContent-Lengthwhen known, mid-stream tripwire for chunked). Response bodies are deliberately not capped — SSE streams are long-lived. Added reqwestconnect_timeout(10 s) plus a per-request deadline (30 s, connect→response headers → 504 on expiry); no total timeout, so it can't kill open SSE channels.--scope ""injected an empty header:derive_scopenow filters empty/whitespace CLI overrides exactly like theAVER_DEFAULT_SCOPEpath (falls through to git/env/global).HeaderValueonce at startup; a misconfigured scope now fails fast with a clear error./mcp/mcpdouble path:join_upstreamcollapses a duplicated/mcpprefix (incl./mcp/and query-string variants), so the shim URL works with or without a trailing/mcp. Contract also documented in--upstreamhelp text.tests/proxy_integration.rsspins up real in-process upstream + shim servers on ephemeral ports (offline, deterministic).Test evidence
cargo test -p aver-scope-shim— 21 passed, 0 failed:proxy_integration(9): scope header injection; no-scope passthrough (and client-suppliedX-Aver-Scopeis stripped, never trusted); configured scope replaces forged client header; SSE streams incrementally (upstream sends chunk 1, parks on aNotify; test asserts the client reads chunk 1 before releasing chunk 2 — would deadlock under store-and-forward); 413 for over-cap body with knownContent-Length; 413 for over-cap chunked upload (mid-stream cap); 1 MiB body passes through intact; upstream hang → 504;/mcp,/mcp/, and/all reach upstream/mcp.scope_derivation(8, incl. 1 new): empty/whitespace--scopefalls through like empty env.join_upstreampath normalization, scope header-value validation.cargo fmtclean;cargo clippy -p aver-scope-shim --all-targets -- -D warningsclean.Notes
#[ignore], nodoc/adr/*.mdedits, noautoresearch.jsonlchanges.futures-util 0.3(already in the tree transitively); tokio gainstime/syncfeatures.