Skip to content

Commit c8d5751

Browse files
committed
fix: use fail-secure SSL parsing (only explicit 'false' disables verification)
- Change from '== true' to '!= false' for fail-secure behavior - Invalid/unknown values now keep SSL verification ENABLED - Add tests for yes/no values to document behavior
1 parent a92c26f commit c8d5751

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

src/fetch/src/mcp_server_fetch/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
# Set MCP_FETCH_SSL_VERIFY=false to disable SSL certificate verification.
2929
# This is useful for internal servers with self-signed certificates.
3030
# WARNING: Disabling SSL verification reduces security. Only use in trusted environments.
31-
SSL_VERIFY = os.getenv("MCP_FETCH_SSL_VERIFY", "true").lower() == "true"
31+
# NOTE: Only explicit "false" disables verification; any other value keeps it enabled (fail-secure).
32+
SSL_VERIFY = os.getenv("MCP_FETCH_SSL_VERIFY", "true").lower() != "false"
3233

3334
DEFAULT_USER_AGENT_AUTONOMOUS = "ModelContextProtocol/1.0 (Autonomous; +https://github.com/modelcontextprotocol/servers)"
3435
DEFAULT_USER_AGENT_MANUAL = "ModelContextProtocol/1.0 (User-Specified; +https://github.com/modelcontextprotocol/servers)"

src/fetch/tests/test_ssl.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,43 +68,65 @@ def test_ssl_verify_FALSE_all_caps(self, monkeypatch):
6868

6969
assert server_module.SSL_VERIFY is False
7070

71-
def test_ssl_verify_invalid_value_defaults_to_disabled(self, monkeypatch):
72-
"""Invalid values should result in SSL verification being disabled (not 'true')."""
71+
def test_ssl_verify_invalid_value_stays_enabled(self, monkeypatch):
72+
"""Invalid/unknown values should keep SSL verification ENABLED (fail-secure)."""
7373
monkeypatch.setenv("MCP_FETCH_SSL_VERIFY", "invalid")
74-
74+
7575
import mcp_server_fetch.server as server_module
7676
importlib.reload(server_module)
77-
78-
# Since "invalid".lower() != "true", SSL_VERIFY will be False
79-
assert server_module.SSL_VERIFY is False
8077

81-
def test_ssl_verify_empty_string_defaults_to_disabled(self, monkeypatch):
82-
"""Empty string should result in SSL verification being disabled."""
78+
# Fail-secure: only explicit "false" disables SSL verification
79+
assert server_module.SSL_VERIFY is True
80+
81+
def test_ssl_verify_empty_string_stays_enabled(self, monkeypatch):
82+
"""Empty string should keep SSL verification ENABLED (fail-secure)."""
8383
monkeypatch.setenv("MCP_FETCH_SSL_VERIFY", "")
84-
84+
8585
import mcp_server_fetch.server as server_module
8686
importlib.reload(server_module)
87-
88-
assert server_module.SSL_VERIFY is False
8987

90-
def test_ssl_verify_0_is_disabled(self, monkeypatch):
91-
"""'0' should result in SSL verification being disabled."""
88+
# Fail-secure: only explicit "false" disables SSL verification
89+
assert server_module.SSL_VERIFY is True
90+
91+
def test_ssl_verify_0_stays_enabled(self, monkeypatch):
92+
"""'0' should keep SSL verification ENABLED (fail-secure, only 'false' disables)."""
9293
monkeypatch.setenv("MCP_FETCH_SSL_VERIFY", "0")
93-
94+
9495
import mcp_server_fetch.server as server_module
9596
importlib.reload(server_module)
96-
97-
assert server_module.SSL_VERIFY is False
9897

99-
def test_ssl_verify_1_is_disabled(self, monkeypatch):
100-
"""'1' should result in SSL verification being disabled (only 'true' enables it)."""
98+
# Fail-secure: only explicit "false" disables SSL verification
99+
assert server_module.SSL_VERIFY is True
100+
101+
def test_ssl_verify_1_stays_enabled(self, monkeypatch):
102+
"""'1' should keep SSL verification ENABLED (fail-secure)."""
101103
monkeypatch.setenv("MCP_FETCH_SSL_VERIFY", "1")
102-
104+
103105
import mcp_server_fetch.server as server_module
104106
importlib.reload(server_module)
105-
106-
# Only "true" (case-insensitive) enables SSL verification
107-
assert server_module.SSL_VERIFY is False
107+
108+
# Fail-secure: only explicit "false" disables SSL verification
109+
assert server_module.SSL_VERIFY is True
110+
111+
def test_ssl_verify_yes_stays_enabled(self, monkeypatch):
112+
"""'yes' should keep SSL verification ENABLED (fail-secure)."""
113+
monkeypatch.setenv("MCP_FETCH_SSL_VERIFY", "yes")
114+
115+
import mcp_server_fetch.server as server_module
116+
importlib.reload(server_module)
117+
118+
# Fail-secure: only explicit "false" disables SSL verification
119+
assert server_module.SSL_VERIFY is True
120+
121+
def test_ssl_verify_no_stays_enabled(self, monkeypatch):
122+
"""'no' should keep SSL verification ENABLED (fail-secure, only 'false' disables)."""
123+
monkeypatch.setenv("MCP_FETCH_SSL_VERIFY", "no")
124+
125+
import mcp_server_fetch.server as server_module
126+
importlib.reload(server_module)
127+
128+
# Fail-secure: only explicit "false" disables SSL verification
129+
assert server_module.SSL_VERIFY is True
108130

109131

110132
class TestSSLErrorHandling:

0 commit comments

Comments
 (0)