Skip to content

fix(tools): percent-encode path parameter values in RestApiTool - #6676

Open
prasanna8585 wants to merge 1 commit into
google:mainfrom
prasanna8585:fix/rest-api-tool-path-param-encoding
Open

fix(tools): percent-encode path parameter values in RestApiTool#6676
prasanna8585 wants to merge 1 commit into
google:mainfrom
prasanna8585:fix/rest-api-tool-path-param-encoding

Conversation

@prasanna8585

Copy link
Copy Markdown

Path parameter values passed to RestApiTool come from the model's tool-call arguments and were substituted into the request URL with no escaping (self.endpoint.path.format(**path_params)). This allowed a value containing /, .., ?, or # to redirect the outgoing request -- including this tool's configured auth credentials -- to a path or query parameter the OpenAPI spec never declared.

Fix: percent-encode each path parameter value with urllib.parse.quote(value, safe="") before substitution, so / is escaped along with everything else and a value can never introduce a new path segment.

Added a regression test (test_prepare_request_params_path_param_is_percent_encoded) covering both the path-traversal and query/fragment-smuggling cases. Full tests/unittests/tools/openapi_tool/ suite (260 tests) passes unchanged.

Path parameter values passed to RestApiTool ultimately originate from
the model's tool-call arguments and were substituted into the request
URL via str.format() with no escaping. An unescaped value could:

- Contain '/' or '..' segments, redirecting the request to a
  different, undeclared path on the same host than the one the
  OpenAPI spec's path template (and this tool's configured auth
  credentials) were scoped to.
- Contain '?' or '#', which the existing query-string-recovery logic
  a few lines below would then promote into a real query parameter
  sent on the wire.

Both are now closed by percent-encoding each path parameter value
with urllib.parse.quote(value, safe="") -- including '/' -- before
substitution, so a value can never introduce a new path segment,
query string, or fragment. Adds a regression test covering both
cases; full openapi_tool suite (260 tests) passes unchanged.
@adk-bot adk-bot added the tools [Component] This issue is related to tools label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants