Skip to content

Python: Percent-encode path parameter values in RestApiOperation.build_path#13967

Draft
SergeyMenshykh wants to merge 2 commits intomicrosoft:mainfrom
SergeyMenshykh:fix/python-openapi-path-param-encoding
Draft

Python: Percent-encode path parameter values in RestApiOperation.build_path#13967
SergeyMenshykh wants to merge 2 commits intomicrosoft:mainfrom
SergeyMenshykh:fix/python-openapi-path-param-encoding

Conversation

@SergeyMenshykh
Copy link
Copy Markdown
Member

Apply urllib.parse.quote(safe='') to path parameter values before substitution in build_path(), consistent with the .NET implementation which uses HttpUtility.UrlEncode.

Changes

  • rest_api_operation.py: encode path parameter values per RFC 3986
  • test_sk_openapi.py: add tests for encoded path parameters

Tests

All existing and new build_path tests pass.

Copilot AI review requested due to automatic review settings May 7, 2026 19:49
@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner May 7, 2026 19:49
@SergeyMenshykh SergeyMenshykh self-assigned this May 7, 2026
@SergeyMenshykh SergeyMenshykh moved this to In Review in Agent Framework May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 using urllib.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.

Comment thread python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label May 7, 2026
…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>
@SergeyMenshykh SergeyMenshykh force-pushed the fix/python-openapi-path-param-encoding branch from b62a7d0 to c217d84 Compare May 7, 2026 20:04
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 90% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by SergeyMenshykh's agents

@SergeyMenshykh SergeyMenshykh marked this pull request as draft May 8, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants