Skip to content

fix(fetch): add configurable SSL certificate verification#3179

Open
Tomo1912 wants to merge 2 commits into
modelcontextprotocol:mainfrom
Tomo1912:fix/ssl-verification-508
Open

fix(fetch): add configurable SSL certificate verification#3179
Tomo1912 wants to merge 2 commits into
modelcontextprotocol:mainfrom
Tomo1912:fix/ssl-verification-508

Conversation

@Tomo1912
Copy link
Copy Markdown

@Tomo1912 Tomo1912 commented Jan 5, 2026

Resolves #508

This replaces the earlier closed PR #3171, which has been split into two focused PRs

Description

Added MCP_FETCH_SSL_VERIFY environment variable to control SSL certificate verification. This allows the fetch server to work with internal servers that use self-signed certificates.

Changes

  • Added SSL_VERIFY configuration via MCP_FETCH_SSL_VERIFY env var (default: true)
  • Added verify=SSL_VERIFY to both AsyncClient instances
  • Added comprehensive SSL error handling with helpful error messages
  • Error messages guide users to set MCP_FETCH_SSL_VERIFY=false for self-signed certs

Usage

export MCP_FETCH_SSL_VERIFY=false

⚠️ Security Note: Disabling SSL verification reduces security. Only use in trusted environments with internal servers that have self-signed certificates.

Server Details

Field Value
Server fetch
Changes to SSL/TLS connection handling

Motivation and Context

Users with internal servers using self-signed certificates cannot use the fetch server because SSL verification fails. This change allows users to optionally disable SSL verification while keeping it enabled by default for security.

How Has This Been Tested?

  • ✅ Tested with pyright (0 errors)
  • ✅ Verified SSL_VERIFY env var parsing works correctly
  • ✅ Tested error message formatting

Breaking Changes

None. SSL verification remains enabled by default.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

A follow-up PR with SSRF protection and comprehensive security tests is available at #3180.

@Tomo1912 Tomo1912 force-pushed the fix/ssl-verification-508 branch 4 times, most recently from c8d5751 to 99644a7 Compare January 9, 2026 22:18
@Tomo1912 Tomo1912 force-pushed the fix/ssl-verification-508 branch from e0d7f08 to dc626ba Compare January 19, 2026 22:17
@Tomo1912 Tomo1912 force-pushed the fix/ssl-verification-508 branch from 0576c9a to eea22fc Compare January 27, 2026 12:26
@Tomo1912 Tomo1912 force-pushed the fix/ssl-verification-508 branch 2 times, most recently from 4c72451 to c938f5b Compare February 4, 2026 18:02
@cliffhall cliffhall added bug Something isn't working server-fetch Reference implementation for the Fetch MCP server - src/fetch labels Apr 20, 2026
@BossChaos

This comment was marked as abuse.

Tomo1912 added 2 commits May 25, 2026 15:08
This PR adds Server-Side Request Forgery (SSRF) protection and a comprehensive
security test suite to the fetch MCP server.

- URL scheme validation (only http/https allowed)
- Private IP range blocking (10.x, 172.16-31.x, 192.168.x, 127.x, etc.)
- IPv6 private address blocking (::1, fe80::, fc00::, etc.)
- Dangerous hostname blocking (localhost, metadata services, etc.)
- DNS resolution validation to prevent DNS rebinding
- Configurable via MCP_FETCH_ALLOW_PRIVATE_IPS env var
- Whitelist support via MCP_FETCH_ALLOWED_PRIVATE_HOSTS

- Configurable SSL verification via MCP_FETCH_SSL_VERIFY env var
- Comprehensive SSL error handling with helpful messages

- SSRF protection tests
- Private IP blocking tests
- Input validation tests
- URL scheme validation tests
- Integration tests
- Edge case tests

```bash
export MCP_FETCH_SSL_VERIFY=false

export MCP_FETCH_ALLOW_PRIVATE_IPS=true

export MCP_FETCH_ALLOWED_PRIVATE_HOSTS=internal.company.com,api.local
```

fix: address security review feedback

- Disable follow_redirects to prevent SSRF bypass via open redirects
- Add explicit IP obfuscation detection (decimal/octal/hex formats)
- Fix SSL parsing to be fail-secure (only 'false' disables verification)
- Clean up test headers (remove enterprise roleplay language)
- Add comprehensive tests for IP obfuscation parsing

fix: add octal integer IP parsing and fix test naming

- Add octal integer format parsing (017700000001 = 127.0.0.1)
- Rename SSL test to reflect fail-secure behavior (stays_enabled, not defaults_to_false)
- Add tests for octal integer IP obfuscation
Address review feedback on SSRF protection:

- Add SSRFSafeTransport custom async transport that resolves DNS,
  validates the resolved IP, and replaces the hostname with the
  validated IP before connecting. This eliminates the TOCTOU window
  between validate_url_for_ssrf() and the actual HTTP request.
- Integrate SSRFSafeTransport into fetch_url() and
  check_may_autonomously_fetch_url() replacing direct AsyncClient usage.
- Add 6 DNS rebinding tests including full attack scenario simulation.
- Update existing tests to match new transport-based architecture.
@Tomo1912 Tomo1912 force-pushed the fix/ssl-verification-508 branch from baab765 to 9db0910 Compare May 25, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server-fetch Reference implementation for the Fetch MCP server - src/fetch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp-server-fetch SSL verify Off

3 participants