Repository navigation
fix(cli): bring the MCP transport to parity with REST — constant-time auth, failed-auth limiter, body ceiling - #400
Merged
Conversation
… auth, failed-auth limiter, body ceiling, resilient accept
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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
tole serve --transport mcpwas missing hardening the REST transport already has. This closes the gaps found by the cora 0.19.0 agent-reviewer trial and verified against the code.Why
The serve token is approval authority (see the threat model), so the MCP face must not be the weaker door.
Changes
authmodule (tole-cli lib):ct_eq,bearer_matches(case-insensitive scheme, RFC 7235) andAuthLimiter(fixed window, 10 failures per minute per IP, swept so memory stays bounded). REST now uses it too (same constants and behaviour; the duplicated local code is removed).mcp_http.rs:==);429after 10 failures in a minute, even for the right token until the window rolls over (REST parity);413: a declaredContent-Lengthbefore any byte is read, a chunked body while it streams (http_body_util::Limited), so neither is buffered whole. Read errors and timeouts stay400;accept()error (EMFILE, ECONNABORTED, ...) is logged and the loop continues with a 50 ms pause instead of ending the server and every session;timeout()around the synchronous auth check (it had no await point, so it never fired) is removed; the header read stays bounded byheader_read_timeout.Behaviour changes to know about
bearerworks), like REST. It used to require exactlyBearer.Testing
mcp_http_hardeningtests: valid request (both scheme spellings), 401 x10 then 429 even with the right token, declared 2 MiB body gives 413, chunked 3 MiB body gives 413. All 4 fail on the old code and pass now (run 3 times).auth(constant-time compare, bearer matching, limiter window/recovery/sweep) and for the bounded body collector (streamed overflow, exact ceiling).serve_http_hardening,serve_approvals) pass. Note:serve_http_hardeningis already flaky on develop (about 1 run in 6 fails at server start, also without this change); not touched here.cargo check --no-default-featurespass; cora review --staged clean.Refs the MCP findings from the cora 0.19.0 agent-reviewer scan