Skip to content

Commit fe97d7a

Browse files
committed
feat(fetch): add SSRF protection and comprehensive security test suite
## Summary This PR adds Server-Side Request Forgery (SSRF) protection and a comprehensive security test suite to the fetch MCP server. ## Security Features Added ### SSRF Protection - 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 ### SSL Configuration - Configurable SSL verification via MCP_FETCH_SSL_VERIFY env var - Comprehensive SSL error handling with helpful messages ### Test Suite (71 tests) - SSRF protection tests - Private IP blocking tests - Input validation tests - URL scheme validation tests - Integration tests - Edge case tests ## Configuration ```bash # Disable SSL verification for self-signed certs export MCP_FETCH_SSL_VERIFY=false # Allow private IPs (use with caution) export MCP_FETCH_ALLOW_PRIVATE_IPS=true # Whitelist specific internal hosts export MCP_FETCH_ALLOWED_PRIVATE_HOSTS=internal.company.com,api.local ```
1 parent 862e717 commit fe97d7a

File tree

6 files changed

+1076
-8
lines changed

6 files changed

+1076
-8
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ requires = ["hatchling"]
3333
build-backend = "hatchling.build"
3434

3535
[tool.uv]
36-
dev-dependencies = ["pyright>=1.1.389", "ruff>=0.7.3"]
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+
]
42+
43+
[tool.pytest.ini_options]
44+
asyncio_mode = "auto"
45+
testpaths = ["tests"]

0 commit comments

Comments
 (0)