Validate static_map_image_tool style path#151
Open
mattpodwysocki wants to merge 3 commits intomainfrom
Open
Conversation
…atic map URL - Add regex validation to the style parameter to prevent path traversal attacks; accepts only username/style-id with alphanumeric chars, hyphens, and underscores - Apply encodeURIComponent() to each style segment before URL interpolation - Return public URL (without access_token) in text content to avoid leaking credentials to the model context; token is still used internally for the fetch and the MCP Apps iframe URL Reported via HackerOne (2026-03-18) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ctufts
reviewed
Mar 20, 2026
Valiunia
reviewed
Mar 20, 2026
| style: z | ||
| .string() | ||
| .regex( | ||
| /^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/, |
Contributor
There was a problem hiding this comment.
would something like path.resolve(), path.normalize() be better than regex?
Contributor
There was a problem hiding this comment.
maybe not "better" but in addition to regex
Contributor
Author
There was a problem hiding this comment.
Good question — but path.resolve()/path.normalize() are the wrong fit here. They operate on filesystem paths and would canonicalize a traversal payload (e.g. ../../tokens/v2 → /tokens/v2) rather than reject it. The goal is to validate that the input matches a known-good format, not to sanitize an arbitrary path. A whitelist regex that only accepts username/style-id (alphanumeric, hyphens, underscores, exactly one slash) is the right approach — anything outside that shape is rejected outright.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ctufts
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a path traversal vulnerability issue in
static_map_image_tool.Path traversal fix: The
styleparameter was an unvalidatedz.string(), allowing a crafted value like../../tokens/v2to escape the/styles/v1/URL path and proxy authenticated requests to arbitrary Mapbox API endpoints using the server operator's access token. Added a regex constraint (/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/) that accepts only validusername/style-idformat. Also applyencodeURIComponent()to each segment before URL interpolation.Credentials leak fix: The full URL including
?access_token=TOKENwas returned as text content and exposed to the model context. The token is only needed internally for the HTTP fetch and the MCP Apps iframe. Changed to return a public URL (without the token) in the text content block.Test plan
rejects style values with path traversal patterns— verifies traversal payloads (../../tokens/v2,../styles, etc.) are rejected withisError: trueaccess_token=is not present in text content🤖 Generated with Claude Code