Skip to content

fix(kernels): prevent output files from escaping the target path - #1189

Merged
stevemessick merged 2 commits into
Kaggle:mainfrom
sridipbasu:fix/kernels-output-path-containment
Sep 8, 2026
Merged

fix(kernels): prevent output files from escaping the target path#1189
stevemessick merged 2 commits into
Kaggle:mainfrom
sridipbasu:fix/kernels-output-path-containment

Conversation

@sridipbasu

Copy link
Copy Markdown
Collaborator

Summary

While looking at the kaggle kernels output flow, I found that a server-provided file name could cause the CLI to write a file outside the directory given with --path.

For example, if the file name was ../outside.txt, the CLI would join it directly with the target directory and write the file outside that directory.

The same issue also happens with absolute paths. This means the CLI was trusting the file name returned by the server without checking that the final path was still inside the requested directory.

Fix

I added a path containment check before downloading the file.

The check uses the existing _is_within_directory helper and makes sure the resolved output path stays inside the requested --path.

If the file would escape the directory, the CLI now refuses to download it instead of writing the file.

Normal nested output paths such as sub/dir/result.csv still work as before.

Tests

I added regression tests for:

  • ../outside.txt
  • absolute paths
  • valid nested paths

The tests also check that files with unsafe paths are rejected before they are fetched.

Ran:

pytest tests/unit/test_kernels_output_paths.py test_kernels_logs.py test_cli_kernels.py test_download_file_paths.py

pytest tests/unit

black --check

All unit tests pass: 1346 passed.

I also checked the new tests against the old implementation. The traversal and absolute-path tests failed before the fix and pass with the fix.

@sridipbasu sridipbasu self-assigned this Sep 6, 2026
@sridipbasu sridipbasu added the bug Something isn't working label Sep 6, 2026
@sridipbasu
sridipbasu force-pushed the fix/kernels-output-path-containment branch from 71a0421 to 1fc3322 Compare September 6, 2026 10:59
@stevemessick
stevemessick merged commit 68dcbdc into Kaggle:main Sep 8, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants