fix: reject RestApiTool path params with '.' or '..' segments - #7066
Open
artemkulyk wants to merge 2 commits into
Open
fix: reject RestApiTool path params with '.' or '..' segments#7066artemkulyk wants to merge 2 commits into
artemkulyk wants to merge 2 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
quote(safe="") leaves '.' literal, so model-supplied '..' still reaches the wire as encoded-slash traversal. Reject those segments before encoding so backends that decode %2F cannot leave the declared path.
artemkulyk
force-pushed
the
fix/rest-api-tool-dot-segment-path
branch
from
September 9, 2026 00:23
249777b to
4cba603
Compare
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
RestApiToolpercent-encodes path parameters withquote(value, safe="")and documents that this prevents a model-supplied value from steering the request onto an undeclared path.quote()never encodes., so../../admin/secretis sent as..%2F..%2Fadmin%2Fsecret. Backends that decode%2Fand then merge dot-segments can dispatch that request — with the tool's credentials — to a path the OpenAPI spec never declared.Solution:
Reject a path parameter if any
/- or\-separated segment is exactly.or.., then keepquote(safe=""). Slash-containing IDs such asfoo/barare still encoded asfoo%2Fbar. Invalid values fail closed incall()as an{"error": ...}result; no HTTP request is sent.Testing Plan
Unit Tests:
New coverage:
_encode_path_paramrejects.,..,../../admin/v1/tenants,foo/../bar,..\admin,./x; still encodesfoo/bar,?/#,file..txt,.gitignore,ok.txt.call()with a traversal name returns an error and does not call_request.Manual End-to-End (E2E) Tests:
OpenAPI spec
GET /files/{name}against a local HTTP server:args={"name": "../../admin/secret"}→{"error": "... parent-directory segments."}, no wire request.args={"name": "ok.txt"}→GET /files/ok.txtsucceeds.Checklist
Additional context
Google VRP 557701521 was closed as Infeasible (not tracked as a security bug) with a request to file this publicly. I have signed the Google CLA.
Made with Cursor