Python: Percent-encode path parameter values in RestApiOperation.build_path#13967
Draft
SergeyMenshykh wants to merge 2 commits intomicrosoft:mainfrom
Draft
Python: Percent-encode path parameter values in RestApiOperation.build_path#13967SergeyMenshykh wants to merge 2 commits intomicrosoft:mainfrom
SergeyMenshykh wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates RestApiOperation.build_path() to percent-encode path parameter values before substituting them into the path template, and adds unit tests to validate encoding behavior for special characters and traversal-like inputs.
Changes:
- Percent-encode path parameter values during
build_path()substitution usingurllib.parse.quote(..., safe=""). - Add unit tests ensuring reserved characters (e.g.,
/,?,#, spaces) are encoded in path params. - Add a unit test ensuring traversal-like strings don’t introduce extra path segments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py | Applies percent-encoding to path parameter substitutions in build_path(). |
| python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py | Adds coverage for encoding special characters and traversal-like inputs in build_path(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…route traversal Apply urllib.parse.quote(safe='') to path parameter values in RestApiOperation.build_path() before URL substitution. This encodes /, ?, #, %, and spaces, preventing attackers from injecting path separators or dot-segments via LLM-supplied parameter values. Addresses issue 115044 (Sev3). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b62a7d0 to
c217d84
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.
Apply
urllib.parse.quote(safe='')to path parameter values before substitution inbuild_path(), consistent with the .NET implementation which usesHttpUtility.UrlEncode.Changes
rest_api_operation.py: encode path parameter values per RFC 3986test_sk_openapi.py: add tests for encoded path parametersTests
All existing and new
build_pathtests pass.