Skip to content

Comments

Security hardening: fix auth bypass, SSRF, MCP vulnerabilities (issue #68)#70

Open
janhilgard wants to merge 3 commits intowaybarrios:mainfrom
janhilgard:security-hardening-issue-68
Open

Security hardening: fix auth bypass, SSRF, MCP vulnerabilities (issue #68)#70
janhilgard wants to merge 3 commits intowaybarrios:mainfrom
janhilgard:security-hardening-issue-68

Conversation

@janhilgard
Copy link
Collaborator

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:

  • Auth bypass on Anthropic endpoints: Added verify_api_key + check_rate_limit dependencies to /v1/messages, /v1/messages/count_tokens, /v1/status, /v1/cache/stats, /v1/cache
  • MCP skip_security_validation bypass: Removed the field entirely from MCPServerConfig — security validation always runs
  • SSRF via URL fetching: Added _validate_url_safety() that blocks private IPs, localhost, link-local, and cloud metadata endpoints before download_image()/download_video()

HIGH fixes:

  • Path traversal in multimodal input: Removed Path.exists() local file checks from process_image_input()/process_video_input() — API only accepts URLs and base64
  • trust_remote_code=True default: Changed to False in SimpleEngine, BatchedEngine, and MLXMultimodalLM; added --trust-remote-code CLI flag for explicit opt-in
  • /v1/mcp/execute sandbox bypass: Now routes through ToolSandbox.validate_tool_execution() before executing
  • MCP allow_unsafe bypass: Removed allow_unsafe parameter and all bypass code from MCPCommandValidator
  • MCP regex bypass: Added newline/CR detection and ${} expansion patterns to dangerous command/arg patterns; added interpreter argument validation (-c, -e, --eval)

MEDIUM fixes:

  • No audio file size limit: Added 100MB upload limit
  • No TTS text length limit: Added 10K character limit
  • Default bind to 0.0.0.0: Changed to 127.0.0.1 with warning when 0.0.0.0 used without --api-key
  • No max_tokens upper bound: Added 128K cap in SamplingParams.__post_init__()
  • MCP config from CWD: Removed ./mcp.json and ./mcp.yaml from search paths (only ~/.config/ now)
  • High-risk MCP tools only warned: Changed _check_high_risk_tool() to raise MCPSecurityError instead of just logging
  • Arbitrary model loading for STT/TTS: Reject unknown models instead of passing through to HuggingFace

LOW fixes:

  • Rate limiter unbounded growth: Added periodic GC of stale clients (every 5 minutes)
  • Exception details leaked: Replaced detail=str(e) with "Internal server error" in 500 responses

NOT included (separate PRs):

Test plan

  • Verify /v1/messages returns 401 without API key when --api-key is set
  • Verify SSRF protection blocks http://169.254.169.254/ and http://localhost/
  • Verify local file paths are rejected by process_image_input()
  • Verify MCPServerConfig(skip_security_validation=True) raises TypeError
  • Verify --trust-remote-code flag is required for models needing it
  • Run uvx black vllm_mlx/ — passes
  • Run existing test suite

Closes #68

🤖 Generated with Claude Code

janhilgard and others added 3 commits February 11, 2026 17:19
…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>
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.

Security audit: authentication bypass, SSRF, and other vulnerabilities

1 participant