Repository navigation
fix(utils): validate data_dir and reject symlinks escaping it - #134
Open
Aloys Jehwin (AloysJehwin) wants to merge 1 commit into
Open
Aloys Jehwin (AloysJehwin) wants to merge 1 commit into
Aloys Jehwin (AloysJehwin) wants to merge 1 commit into
Conversation
list_perf_event_log_files globbed **/*.csv with no checks on data_dir. A missing or non-directory path produced the same 'no csvs ending in perf_event_log found' message as a real empty directory, and glob follows symlinks, so a link under data_dir could pull in a CSV from anywhere on the filesystem. Fixes microsoft#18 Signed-off-by: Aloys Jehwin <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #134 +/- ##
==========================================
+ Coverage 78.03% 78.23% +0.20%
==========================================
Files 23 23
Lines 1079 1089 +10
Branches 109 113 +4
==========================================
+ Hits 842 852 +10
Misses 187 187
Partials 50 50
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved symlink traversal and time-of-check/time-of-use risks block approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR validates data_dir and filters CSV symlinks that resolve outside it.
Changes:
- Rejects missing or non-directory paths.
- Adds symlink containment checks.
- Expands filesystem-backed test coverage.
File summaries
| File | Description |
|---|---|
tests/test_commons/test_utils.py |
Updates mocks and adds filesystem-backed validation and symlink tests. |
src/vasim/commons/utils.py |
Validates directories and filters external symlinks. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| continue | ||
| # glob follows symlinks, so a link under data_dir can resolve anywhere | ||
| # on the filesystem; keep only what really lives under the directory. | ||
| if not file.is_file() or not file.resolve().is_relative_to(root): |
| perf_event_log_files = [file for file in csv_files if file.stem.endswith("perf_event_log")] | ||
| root = data_dir.resolve() | ||
| perf_event_log_files = [] | ||
| for file in data_dir.glob("**/*.csv"): |
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.
Fixes #18
Picking up the sanitization ask on
list_perf_event_log_files. Two things the baredata_dir.glob("**/*.csv")was letting through:A
data_dirthat doesn't exist, or that's a file rather than a directory, globs to nothing and you get "no csvs ending in perf_event_log found in data_dir" — the same message a genuinely empty directory gives. That sends you looking for missing CSVs when the real problem is the path. Those now say so explicitly.The bigger one is that
globfollows symlinks, so a link sitting underdata_dircan resolve to a CSV anywhere on the filesystem and get read as trace data. Each match is now resolved and kept only if it still lands underdata_dir. A symlink that stays inside the directory keeps working — I didn't want to break anyone laying out traces that way — and there's a test for both directions.Return values are unchanged for the normal case: I glob the unresolved
data_dirand only resolve for the containment check, so callers get the same paths they got before.The three existing tests mock
Path.globand passtests/tests_commons, which isn't a real directory, so the newis_dir()check would have short-circuited them — they now patchis_diralongsideglob. I also added five filesystem-backed tests that use a real temp directory instead of mocks.black, isort and pydocstringformatter are clean on both files. The full suite errors on 10 tests locally from a missing pandas, but identically on a clean
main— unrelated to this change.