Skip to content

fix(mcp): name the offending path in computeURIFilepath localize error - #1381

Merged
guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
PratikDhanave:fix/resource-localize-error-names-path
Oct 12, 2026
Merged

guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
PratikDhanave:fix/resource-localize-error-names-path

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

computeURIFilepath formats filepath.Localize's error-path return value:

uriFilepathRel, err := filepath.Localize(strings.TrimPrefix(uri.Path, "/"))
if err != nil {
    return "", fmt.Errorf("%q cannot be localized: %w", uriFilepathRel, err)
}

On error, filepath.Localize returns "", so the message is always "" cannot be localized: ... and never names the path that failed — unhelpful precisely on the path-traversal rejection path where you want to see the offending input. Format the input relative path instead.

Added a regression test asserting the offending path appears in the error (fails before the fix: "" cannot be localized: invalid path; passes after). go build ./..., go test ./mcp/ pass.

computeURIFilepath formatted filepath.Localize's error-path return value, which
is always "" on error, so the message was always `"" cannot be localized: ...`
and never named the path that failed — unhelpful on the path-traversal
rejection path. Format the input relative path instead.

Add a regression test asserting the offending path appears in the error.
@guglielmo-san
guglielmo-san merged commit 452ac5a into modelcontextprotocol:main Oct 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants