Files
semantic-kernel/python/semantic_kernel
Eduard van Valkenburg c096a5e276 Python: Encode and validate session download filenames (#14520)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Keep raw session download filenames as filename data when constructing
request URLs, while preserving ordinary nested paths.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

- URL-encode `remote_file_name`, preserving `/` separators for nested
paths.
- Reject literal `.` and `..` path components with
`FunctionExecutionException` before authentication or a request, and
document this constraint.
- Add HTTPX transport-based tests for ordinary and nested filenames,
special characters, literal percent escapes, and early rejection.
Confirm that `download_file` remains outside normal kernel-function
registration.

**Validation** (from `python/`, using an existing uv-managed
environment):

- `uv run --no-sync --no-env-file python -m pytest
tests/unit/core_plugins/test_sessions_python_plugin.py
--disable-warnings`: passed, 74 tests; 14 warnings.
- `uv run --no-sync --no-env-file python -m ruff check --no-cache
semantic_kernel/core_plugins/sessions_python_tool/sessions_python_plugin.py
tests/unit/core_plugins/test_sessions_python_plugin.py`: passed.
- `uv run --no-sync --no-env-file python -m ruff format --check
--no-cache
semantic_kernel/core_plugins/sessions_python_tool/sessions_python_plugin.py
tests/unit/core_plugins/test_sessions_python_plugin.py`: passed.
- `uv run --no-sync --no-env-file python -m mypy --config-file mypy.ini
--follow-imports=silent
semantic_kernel/core_plugins/sessions_python_tool/sessions_python_plugin.py`:
passed.

Installed pre-commit hooks passed during the commit, including
pyupgrade, Ruff, Ruff formatting, and Bandit.

The repository-wide build, all-files pre-commit checks, and full
unit/integration suites were not run.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2026-10-06 08:00:41 +00:00
..
2024-10-10 22:33:42 +00:00
2024-03-28 15:10:28 +00:00