Security hardening: fix auth bypass, SSRF, MCP vulnerabilities (issue #68)#70
Security hardening: fix auth bypass, SSRF, MCP vulnerabilities (issue #68)#70janhilgard wants to merge 3 commits intowaybarrios:mainfrom
Conversation
…rrios#68) Fix 17 security issues from comprehensive security audit: CRITICAL: - Add auth + rate limiting to Anthropic /v1/messages endpoints - Remove skip_security_validation bypass from MCP config - Add SSRF protection (_validate_url_safety) to image/video downloads HIGH: - Remove local file path traversal from process_image/video_input - Change trust_remote_code default to False (SimpleEngine, BatchedEngine, MLLM) - Add --trust-remote-code CLI flag for explicit opt-in - Route /v1/mcp/execute through ToolSandbox validation - Remove allow_unsafe bypass from MCPCommandValidator - Add interpreter arg validation (-c, -e) to MCP security - Add newline/CR injection detection to MCP patterns MEDIUM: - Add 100MB audio upload size limit - Add 10K char TTS input length limit - Change default host from 0.0.0.0 to 127.0.0.1 - Add max_tokens upper bound (128K) in SamplingParams - Remove CWD config paths (./mcp.json) from MCP search - Block high-risk MCP tools instead of just warning - Reject unknown STT/TTS models instead of passing through LOW: - Add periodic cleanup of stale clients in rate limiter - Sanitize exception details in error responses (500s) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests now verify that removed features (allow_unsafe, skip_security_validation) are properly rejected, and that high-risk tools raise MCPSecurityError instead of just logging a warning. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests for process_image_input and process_video_input updated to verify that local file paths are properly rejected (path traversal prevention). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cd4168c to
a07740d
Compare
|
@waybarrios This PR has been freshly rebased onto main and is mergeable. All 20+ security fixes are still missing from main — PR #4 added the auth/rate-limit infrastructure, but this PR applies it to unprotected endpoints (
Issue #68 is still open. Would appreciate a review when you get a chance. |
|
@waybarrios, @janhilgard: independent review of the security hardening PR. Status notePR is MERGEABLE on current main per the PR JSON. Last activity was Mar 21 with janhilgard`s freshly-rebased status comment confirming the PR still applies. Issue #68 is still open and tracks the underlying audit findings. Scope verificationPer the PR description, this addresses 17 of the 25 vulnerabilities in #68. The architectural shape of each fix is the right one:
These are all standard security best practices and the right shapes for the vulnerabilities described in #68. RecommendationMerge candidate based on the description and the architectural approach. A line-by-line audit of all 17 fixes is beyond what I can do in a drive-by review, but nothing in the description or the comment thread raises a red flag, and ~2 months of merge delay on critical-path security work is much worse than the marginal risk of any individual fix being slightly wrong (which can be patched in a follow-up). The 8 vulnerabilities not covered by this PR can land in a follow-up. |
|
This PR still has relevant security fixes that are not yet in
Closing due to merge conflicts — the fixes should be re-submitted in a fresh PR against current |
Summary
Comprehensive security hardening addressing 17 of the 25 vulnerabilities identified in #68. This PR fixes all actionable items in a single commit.
CRITICAL fixes:
verify_api_key+check_rate_limitdependencies to/v1/messages,/v1/messages/count_tokens,/v1/status,/v1/cache/stats,/v1/cacheskip_security_validationbypass: Removed the field entirely fromMCPServerConfig— security validation always runs_validate_url_safety()that blocks private IPs, localhost, link-local, and cloud metadata endpoints beforedownload_image()/download_video()HIGH fixes:
Path.exists()local file checks fromprocess_image_input()/process_video_input()— API only accepts URLs and base64trust_remote_code=Truedefault: Changed toFalseinSimpleEngine,BatchedEngine, andMLXMultimodalLM; added--trust-remote-codeCLI flag for explicit opt-in/v1/mcp/executesandbox bypass: Now routes throughToolSandbox.validate_tool_execution()before executingallow_unsafebypass: Removedallow_unsafeparameter and all bypass code fromMCPCommandValidator${}expansion patterns to dangerous command/arg patterns; added interpreter argument validation (-c,-e,--eval)MEDIUM fixes:
127.0.0.1with warning when0.0.0.0used without--api-keySamplingParams.__post_init__()./mcp.jsonand./mcp.yamlfrom search paths (only~/.config/now)_check_high_risk_tool()to raiseMCPSecurityErrorinstead of just loggingLOW fixes:
detail=str(e)with"Internal server error"in 500 responsesNOT included (separate PRs):
Test plan
/v1/messagesreturns 401 without API key when--api-keyis sethttp://169.254.169.254/andhttp://localhost/process_image_input()MCPServerConfig(skip_security_validation=True)raisesTypeError--trust-remote-codeflag is required for models needing ituvx black vllm_mlx/— passesCloses #68
🤖 Generated with Claude Code