Skip to content

Commit 7703e1e

Browse files
committed
feat(fetch): add SSRF protection and comprehensive security test suite
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
1 parent 760829a commit 7703e1e

File tree

6 files changed

+1498
-865
lines changed

6 files changed

+1498
-865
lines changed

src/fetch/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,45 @@ This can be customized by adding the argument `--user-agent=YourUserAgent` to th
170170

171171
The server can be configured to use a proxy by using the `--proxy-url` argument.
172172

173+
### Customization - Private Network Access
174+
175+
By default, the server blocks requests to private IP ranges (10.x.x.x, 192.168.x.x, 127.x.x.x, etc.) to prevent SSRF attacks. If you need to access internal services, you can configure this behavior:
176+
177+
**Allow all private IPs (use with caution):**
178+
179+
```json
180+
{
181+
"mcpServers": {
182+
"fetch": {
183+
"command": "uvx",
184+
"args": ["mcp-server-fetch"],
185+
"env": {
186+
"MCP_FETCH_ALLOW_PRIVATE_IPS": "true"
187+
}
188+
}
189+
}
190+
}
191+
```
192+
193+
**Whitelist specific internal hosts:**
194+
195+
```json
196+
{
197+
"mcpServers": {
198+
"fetch": {
199+
"command": "uvx",
200+
"args": ["mcp-server-fetch"],
201+
"env": {
202+
"MCP_FETCH_ALLOWED_PRIVATE_HOSTS": "internal.company.com,api.local"
203+
}
204+
}
205+
}
206+
}
207+
```
208+
209+
> [!WARNING]
210+
> Allowing private network access can expose internal services. Only enable this in trusted environments.
211+
173212
## Windows Configuration
174213

175214
If you're experiencing timeout issues on Windows, you may need to set the `PYTHONIOENCODING` environment variable to ensure proper character encoding:

src/fetch/pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ requires = ["hatchling"]
3333
build-backend = "hatchling.build"
3434

3535
[tool.uv]
36-
dev-dependencies = ["pyright>=1.1.389", "ruff>=0.7.3", "pytest>=8.0.0", "pytest-asyncio>=0.21.0"]
36+
dev-dependencies = [
37+
"pyright>=1.1.389",
38+
"ruff>=0.7.3",
39+
"pytest>=7.0.0",
40+
"pytest-asyncio>=0.21.0",
41+
]
3742

3843
[tool.pytest.ini_options]
39-
testpaths = ["tests"]
4044
asyncio_mode = "auto"
45+
testpaths = ["tests"]

0 commit comments

Comments
 (0)