You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title: Gateway-Level Input Validation & Output Sanitization Goal: Add a first-class validation/sanitization layer to our MCP Gateway so that every inbound parameter (tool args, resource URIs, prompt vars) is validated and every outbound payload is sanitized before execution or delivery. Why now: We've seen live PoCs where malicious strings passed straight into shells or SQL. Building a reference implementation lets us battle-test these controls and ship an experimental proof-of-concept that we can upstream into the MCP spec as a formal security enhancement.
🧭 Type of Feature
Security hardening
New functionality (experimental)
🙋♂️ User Story 1 — Path Traversal Defense
As a: Platform security engineer I want: the gateway to normalize and confine all resource paths to declared roots So that: traversal payloads like ../../../etc/passwd are blocked before any file I/O.
✅ Acceptance Criteria
Scenario: Reject resource path traversalGiven MCP_GW_ROOT="/srv/data"When a client requests "/srv/data/../../secret.txt"Then respond 400 "invalid_path"And MUST NOT read files outside "/srv/data"
🙋♂️ User Story 2 — Dangerous-Sink Parameter Validation
As a: Tool developer I want: the runtime to escape or reject shell/SQL metas in parameters So that:"bobbytables.jpg; cat /etc/passwd" cannot trigger command injection.
✅ Acceptance Criteria
Scenario: Prevent command injection via filenameGiven tool "image.convert" shells out with a filename arg
When filename == "bobbytables.jpg; cat /etc/passwd"Then the runtime MUST
* escape the value per safe-exec rules OR
* reject with 422 "validation_failed"And no unintended command runs
🙋♂️ User Story 3 — Output Sanitization Guard
As a: Client integrator I want: control chars & mismatched MIME types stripped or fixed on every response So that: hostile escape sequences aren't fed back into UIs or LLMs.
✅ Acceptance Criteria
Scenario: Sanitize tool outputGiven a tool returns text containing ASCII 0x1B
When the gateway serializes the JSON-RPC response
Then remove/encode unsafe control chars
And ensure Content-Type matches sanitized payload
📐 Design Sketch
flowchart TD
subgraph ValidationLayer
A[Inbound JSON-RPC] --> V{Validate<br/>JSONSchema, allow-list}
V --✔--> H[Handler]
V --✖--> E[HTTP 400 / 422]
end
H --> S[Sanitize Response]
S --> O[Outbound JSON-RPC]
Loading
Component / Area
Change
Detail
validation_middleware.py
NEW
Parse params; JSON-Schema or regex allow-list; length & charset limits
Resource Service
UPDATE
read_resource() → normalize_path(), root-confine
Tool Exec Wrapper
UPDATE
subprocess.run(args=list,shell=False); escape or abort on metas
🧭 Epic
Title: Gateway-Level Input Validation & Output Sanitization
Goal: Add a first-class validation/sanitization layer to our MCP Gateway so that every inbound parameter (tool args, resource URIs, prompt vars) is validated and every outbound payload is sanitized before execution or delivery.
Why now: We've seen live PoCs where malicious strings passed straight into shells or SQL. Building a reference implementation lets us battle-test these controls and ship an experimental proof-of-concept that we can upstream into the MCP spec as a formal security enhancement.
🧭 Type of Feature
🙋♂️ User Story 1 — Path Traversal Defense
As a: Platform security engineer
I want: the gateway to normalize and confine all resource paths to declared roots
So that: traversal payloads like
../../../etc/passwdare blocked before any file I/O.✅ Acceptance Criteria
🙋♂️ User Story 2 — Dangerous-Sink Parameter Validation
As a: Tool developer
I want: the runtime to escape or reject shell/SQL metas in parameters
So that:
"bobbytables.jpg; cat /etc/passwd"cannot trigger command injection.✅ Acceptance Criteria
🙋♂️ User Story 3 — Output Sanitization Guard
As a: Client integrator
I want: control chars & mismatched MIME types stripped or fixed on every response
So that: hostile escape sequences aren't fed back into UIs or LLMs.
✅ Acceptance Criteria
📐 Design Sketch
flowchart TD subgraph ValidationLayer A[Inbound JSON-RPC] --> V{Validate<br/>JSONSchema, allow-list} V --✔--> H[Handler] V --✖--> E[HTTP 400 / 422] end H --> S[Sanitize Response] S --> O[Outbound JSON-RPC]validation_middleware.pyread_resource()→normalize_path(), root-confinesubprocess.run(args=list,shell=False); escape or abort on metassanitize_output()removes C0 controls & verifies MIMEALLOWED_ROOTS,VALIDATION_STRICT,SANITIZE_OUTPUTtoggles🔄 Roll-out Plan
EXPERIMENTAL_VALIDATE_IO(off by default).📝 Spec-Draft Clauses (to upstream later)
📣 Next Steps
tests/security/test_validation.py).EXPERIMENTAL_VALIDATE_IOin CI.Once merged, we'll share results with the MCP working groups and iterate on the spec language.