Skip to content

Reject control characters in MCP resource URIs - #257

Merged
MisterVVP merged 1 commit into
dev-extend-production-tutorials-with-mcp-integrationfrom
dev-reject-control-characters-in-mcp-headers
Sep 30, 2026
Merged

MisterVVP merged 1 commit into
dev-extend-production-tutorials-with-mcp-integrationfrom
dev-reject-control-characters-in-mcp-headers

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Prevent CRLF/header injection via user-supplied resource URIs that are copied into the Mcp-Name header and accepted by libcurl.\
  • Enforce URI validation at both protobuf-boundary helpers and the MCP client boundary to fail-fast and avoid emitting attacker-controlled outbound headers.\

Description

  • Add ValidateResourceUri(std::string_view, std::string_view) in examples/tutorials/common/resource_validation.h which rejects empty values and any ASCII control characters (chars < 0x20 and DEL 0x7f).\
  • Update ValidateResourceUriField to reuse ValidateResourceUri for protobuf string values.\
  • Apply validation in Client::ReadResource (in examples/tutorials/common/mcp_client.cpp) before constructing the outbound request and headers, returning the validation error if the URI is invalid.\
  • Add unit tests in tests/unit/mcp_client_test.cpp to cover CRLF/header-injection style input and other control characters, and update tests to set protobuf string values with std::string where needed.\

@MisterVVP MisterVVP added the codex Automatic label added by codex agent. Should not be used label Sep 30, 2026 — with ChatGPT Codex Connector
@MisterVVP MisterVVP self-assigned this Sep 30, 2026
@MisterVVP MisterVVP added AI agent AI agent contribution and removed codex Automatic label added by codex agent. Should not be used labels Sep 30, 2026
@MisterVVP
MisterVVP merged commit 914531a into dev-extend-production-tutorials-with-mcp-integration Sep 30, 2026
19 checks passed
@MisterVVP
MisterVVP deleted the dev-reject-control-characters-in-mcp-headers branch September 30, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant