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
{{ message }}
Repository navigation
Commit 1486ea0
Browse filesBrowse the repository at this point in the historyBrowse files
Refuse a skill URI that is not valid UTF-8 and escape the echoed strings
## Motivation and Context
Three places echoed request data without regard to where it goes.
`skills/get` and `resources/read` with a `params.uri` holding bytes that are not valid UTF-8 answered -32603
instead of -32602. The JSON parser passes such bytes through inside a string, `Skill::Uri.segments` then raised
from `split`, and the refusal's `error_data: { uri: }` could not be generated, which `handle_json` also turns
into Internal error. `Uri.segments` now requires a validly encoded String, so such a URI is not a manifest URI,
and the three Skills refusals put the URI into their error data read as UTF-8 with its invalid bytes replaced.
A `params.uri` that is not a String is not echoed at all, since an Array or Hash could hold such bytes anywhere;
the data then falls back to the message, as for the other refusals.
The "Skill not found" and "Skill file not found" messages carried the URI verbatim to the client and to
the exception reporter, so a URI holding CR, LF, or ESC could forge or recolor a reporter log line. Both messages
now quote the URI with `dump`, which keeps it on one printable ASCII line, and so does the detail reported when
a `skills/get` handler answers for another URI. The older Resource, Tool, and Prompt messages are left as they
are: changing them is a separate decision, while the Skills messages are unreleased.
`MCP::Client` warns on stderr when it excludes a tool from `tools/list` for an invalid `x-mcp-header` definition,
and the warning printed the property names and header values the server chose, raw. The tool name (inspected
first when it is not a String) and the reason are now quoted with `dump` as well, so bidirectional overrides and
control characters cannot reorder or forge the line.
## How Has This Been Tested?
test/mcp/skill_test.rb, test/mcp/server_skills_test.rb, test/mcp/skill/directory_test.rb, and
test/mcp/client_test.rb. Before the fix, `skills/get` with `skill://pdf-processing\xFF/SKILL.md` answered -32603
"Internal error handling skills/get request", `resources/read` with such a URI under a skill root and `skills/get`
with a `params.uri` Hash holding such bytes answered -32603 through `handle_json`, the reporter received
"Skill not found: skill://x\r\nforged..." with the raw CR and LF, and the exclusion warning printed the U+202E
property name and the ESC in the header value unescaped. A binary-tagged `skill://x\xC3\xA9/SKILL.md` given to
`handle` came back with the message and `data.uri` as binary Strings, which json 3.1 refuses to generate (json 3.0
generated them with a deprecation warning, since the bytes are valid UTF-8).
## Breaking Changes
None on the wire. The two messages that now quote the URI were added with the Skills extension, which is
unreleased, and the error code and `data.uri` of a valid UTF-8 URI are unchanged. A String in another encoding
given to `Server#handle` directly now has its bytes read as UTF-8 for `data.uri`, where JSON used to transcode it.
The stderr warning of `MCP::Client` for an excluded tool changes its wording, since it now quotes the two strings.
0 commit comments