fix(kernels): prevent output files from escaping the target path - #1189
Merged
stevemessick merged 2 commits intoSep 8, 2026
Merged
Conversation
sridipbasu
force-pushed
the
fix/kernels-output-path-containment
branch
from
September 6, 2026 10:59
71a0421 to
1fc3322
Compare
stevemessick
approved these changes
Sep 8, 2026
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.
Summary
While looking at the
kaggle kernels outputflow, 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_directoryhelper 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.csvstill work as before.Tests
I added regression tests for:
../outside.txtThe 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.pypytest tests/unitblack --checkAll 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.