Skip to content

Python: fix(sessions): reject directory paths in upload path validation - #14797

Open
Hardik K (hardikkaurani) wants to merge 7 commits into
microsoft:mainfrom
hardikkaurani:fix/sessions-python-tool-upload-directory-validation
Open

Hardik K (hardikkaurani) wants to merge 7 commits into
microsoft:mainfrom
hardikkaurani:fix/sessions-python-tool-upload-directory-validation

Conversation

@hardikkaurani

@hardikkaurani Hardik K (hardikkaurani) commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Motivation and Context

In SessionsPythonTool._validate_local_path_for_upload, paths passed to upload_file are validated against allowed_upload_directories. However, the validation previously did not reject paths pointing directly to an allowed directory or one of its subdirectories.

As a result, these paths passed validation and were returned as valid file paths. upload_file() then attempted to open the directory as a file, causing an unhandled OS error instead of the expected FunctionExecutionException("Access denied: ...").

This aligns upload path validation with the directory validation behavior introduced for download paths in #14791.

Description

  • Updated _validate_local_path_for_upload to reject paths that resolve to an allowed directory or any subdirectory.
  • Updated the docstring to document directory path rejection.
  • Added unit tests in test_sessions_python_plugin.py covering:
    • Rejection of the allowed directory itself.
    • Rejection of subdirectories within allowed directories.
    • Rejection of symlinks pointing to directories.
    • Successful uploads of valid files nested within allowed directories.

Contribution Checklist

@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 15, 2026 11:56
Copilot AI balanced review requested due to automatic review settings November 15, 2026 11:56

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 15, 2026
@hardikkaurani

Hardik K (hardikkaurani) commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

Could you please take a look when you have a moment?

This PR hardens upload path validation in SessionsPythonTool._validate_local_path_for_upload. Previously, passing the allowed directory itself or a directory path inside it was accepted by the path check, leading to an unhandled PermissionError (or IsADirectoryError on Linux) during open(validated_path, "rb") instead of raising FunctionExecutionException("Access denied: ..."). This brings upload path validation in line with the directory validation behavior established for download paths in #14791.

All unit tests and lint checks pass cleanly locally. Thank you for your review!

This branch was successfully deployed

1 active deployment
github-app-auth — 079c12f7 Deployed Nov 15, 2026 by hardikkaurani via add_label #29695
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.

2 participants