Skip to content

Commit 6d9bc79

Browse files
authored
Merge pull request #101 from TheodorNEngoy/codex/security-note
Docs: add security notes for network-exposed MCP servers
2 parents 959cabf + 2975f60 commit 6d9bc79

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
A repository of servers and clients from the following Model Context Protocol tutorials:
44
- [Quickstart](https://modelcontextprotocol.io/quickstart) – a simple MCP weather server
55
- [Building MCP clients](https://modelcontextprotocol.io/tutorials/building-a-client) – an LLM-powered chatbot MCP client
6+
7+
## Security Note
8+
9+
These examples are intentionally minimal. If you expose an MCP server over a network (HTTP/SSE/WebSocket), add authentication and basic hardening (CORS allowlist, request size limits, timeouts, rate limits, and log redaction). See [`SECURITY.md`](./SECURITY.md).

SECURITY.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Security Notes (Quickstart Resources)
2+
3+
These examples are intentionally minimal and optimized for learning. Before using similar patterns in production, apply basic hardening.
4+
5+
## If You Expose An MCP Server Over A Network (HTTP/SSE/WebSocket)
6+
7+
- **Require authentication**: do not expose unauthenticated tool endpoints to the public internet.
8+
- **Treat browsers as hostile**:
9+
- Do not use wildcard CORS (`Access-Control-Allow-Origin: *`) on authenticated endpoints.
10+
- Do not reflect `Origin` without allowlist validation.
11+
- Prefer an explicit origin allowlist.
12+
- **Bound resource usage**:
13+
- Set an explicit maximum request body size.
14+
- Add timeouts to outbound requests.
15+
- Add rate limits (per user/token and/or per IP).
16+
- **Avoid RCE primitives in tools**:
17+
- Avoid `eval` / dynamic code execution.
18+
- Avoid invoking a shell with attacker-controlled input (`exec`, `sh -c`, `shell=True`).
19+
- If you must run commands, enforce strict allowlists and pass arguments as arrays (no shell).
20+
- **Don't leak secrets**: redact `Authorization`, cookies, and API keys from logs.
21+
22+
## Local-Only Usage
23+
24+
If you run these examples locally via stdio transports, your main risks are still:
25+
26+
- accidentally adding dangerous tools (filesystem/shell) without strict controls
27+
- leaking secrets via logs or environment
28+
29+
When in doubt: keep tool capability narrow and add input validation.
30+

0 commit comments

Comments
 (0)