Repository navigation
Python: fix(python): check the full download path in SessionsPythonTool - #14791
Merged
westey (westey-m) merged 3 commits intoNov 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the download-path validation changes.
No open issues 🎉
What changed in this PR
This PR strengthens SessionsPythonTool download-path validation by resolving the entire destination, including filename symlinks, before checking allowed directories.
Changes:
- Validates and returns the fully resolved path, rejects destinations equal to an allowed root, and includes the resolved path in denial logs.
- Adds regression tests for symlinks targeting existing or missing files outside allowed directories and permitted targets inside them.
- Updates the nbQA and pyupgrade pre-commit hooks.
| File | Description |
|---|---|
python/tests/unit/core_plugins/test_sessions_python_plugin.py |
Adds download regression tests for allowed and denied symlink targets. |
python/semantic_kernel/core_plugins/sessions_python_tool/sessions_python_plugin.py |
Resolves complete download paths for allowlist checks and improves denial logging. |
python/.pre-commit-config.yaml |
Updates nbQA to 1.10.0 and pyupgrade to v3.21.2. |
Review effort: Balanced
westey (westey-m)
enabled auto-merge
November 13, 2026 15:56
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 13, 2026
This branch was successfully deployed
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.
Motivation and Context
When
allowed_download_directoriesis set,SessionsPythonTool.download_file()checks that the local path is inside one of the allowed folders. The check only resolved the folder part of the path and then added the file name back without resolving it. When the file name is a symbolic link, the path that was checked and the place the file was actually written could be different, so a path could pass the check and still be written outside the allowed folders.This also brings the Python check in line with how the .NET
SessionsPythonPluginresolves download paths.Description
_validate_local_path_for_downloadnow resolves the whole path, including the file name, withos.path.realpath. It compares that result with the allowed folders and returns the same value, so the path that is checked is the path that is written.allowed/.) are now rejected with the normal "not within allowed download directories" error. Before, they passed the check and failed later when opening the folder for writing.allowed_download_directoriesis not set, and no change to uploads.Validation:
uv run --no-sync pytest tests/unit/core_plugins/test_sessions_python_plugin.py: 89 passedContribution Checklist