Skip to content

Python: normalize OpenAPI allowlist paths before prefix match - #14668

Open
Mangesh Raut (mangeshraut712) wants to merge 2 commits into
microsoft:mainfrom
mangeshraut712:tip/sk-14662-normalize-path-prefix
Open

Mangesh Raut (mangeshraut712) wants to merge 2 commits into
microsoft:mainfrom
mangeshraut712:tip/sk-14662-normalize-path-prefix

Conversation

@mangeshraut712

Copy link
Copy Markdown

Summary

  • Decode %2e/%2E and apply RFC 3986 remove_dot_segments before allowed_base_urls path-prefix matching
  • Closes the gap where /api/../admin and /api/%2e%2e/admin matched an /api allowlist while httpx would request /admin
  • Empty segments (//) preserved to match httpx; other percent-encodings left intact

Tests

  • Rejects .. and %2e%2e escapes under an /api allowlist
  • Still allows /api/./users, /api/users, /api, /api/
  • Still rejects /apiusers (shared prefix chars only)

Fixes #14662

Copilot AI balanced review requested due to automatic review settings October 27, 2026 08:26
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Path-scope bypasses remain, and terminal dot segments lose trailing slashes required for correct allowlist matching.

3 open issues
What changed in this PR

This PR hardens Python OpenAPI URL allowlist validation against same-host path escapes, addressing issue #14662.

Changes:

  • Normalizes request and allowlist paths before prefix matching.
  • Decodes percent-encoded dots and resolves dot segments while preserving empty segments.
  • Adds tests for traversal attempts, valid paths, and prefix boundaries.
File Description
python/​tests/​unit/​connectors/​openapi_plugin/​test_server_url_validator.py Adds rejection and acceptance regression cases.
python/​semantic_kernel/​connectors/​openapi_plugin/​server_url_validator.py Adds path normalization to allowlist prefix matching.

Review effort: Balanced

if segment == ".":
continue
if segment == "..":
if resolved and resolved[-1] != "":
Comment on lines +159 to +160
url_path = _normalize_path(url_path or "/")
base_path = _normalize_path(base_path or "/")
# Absolute paths keep a leading empty segment from the initial "/".
if not resolved:
return "/"
normalized = "/".join(resolved)
Decode %2e/%2E and apply RFC 3986 remove_dot_segments so
allowed_base_urls cannot be escaped with .. or encoded dots.
Matches httpx path normalization; empty segments preserved.

Fixes microsoft#14662
@mangeshraut712

Copy link
Copy Markdown
Author

Rebased onto latest main (CI re-running). Ready for review/merge when you have a chance — thanks.

This branch was successfully deployed

1 active deployment
github-app-auth — 3326fe0c Deployed Oct 27, 2026 by mangeshraut712 via add_label #29472
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

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Python: allowed_base_urls path prefix can be escaped with dot segments (.. / %2e) — validator and HTTP client disagree on the path

2 participants