fix(tools): percent-encode path parameter values in RestApiTool - #6676
Open
prasanna8585 wants to merge 1 commit into
Open
fix(tools): percent-encode path parameter values in RestApiTool#6676prasanna8585 wants to merge 1 commit into
prasanna8585 wants to merge 1 commit into
Conversation
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.
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.
Path parameter values passed to
RestApiToolcome 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. Fulltests/unittests/tools/openapi_tool/suite (260 tests) passes unchanged.