fix(eval): sanitize example_id to prevent path traversal (fixes #78, #79)#80
Open
dex0shubham wants to merge 1 commit into
Open
fix(eval): sanitize example_id to prevent path traversal (fixes #78, #79)#80dex0shubham wants to merge 1 commit into
dex0shubham wants to merge 1 commit into
Conversation
…rail-org#78, StarTrail-org#79) example_id flowed unsanitized into os.path.join output filenames in eval/lib/pixel_query.py, so an id like '../../evil' could write outside output_dir. Add a _safe_stem() helper (Path(x).name) and apply it at all three sites: PixelQueryRenderer.render (StarTrail-org#78), .render_all (missed by the audit), and QueryImageTextRenderer.render (StarTrail-org#79). Add tests/test_pixel_query_paths.py. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@dex0shubham is attempting to deploy a commit to the andylizf's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
example_idis interpolated straight into output filenames viaos.path.joinineval/lib/pixel_query.py, with no sanitization. An id containing path separators(e.g.
../../evil) makes the renderer write files outside the intendedoutput_dir— a path-traversal write.example_idcomes from eval dataset records,so the exposure is running the eval harness over an untrusted/crafted dataset.
Reported in #78 and #79.
What I changed
Added a small
_safe_stem()helper (Path(x).name, which keeps only the final pathcomponent — never a separator, never absolute) and applied it at all three affected
sites:
PixelQueryRenderer.render→{example_id}_query.png(🔒 Path traversal vulnerability in output file path #78)PixelQueryRenderer.render_all→{eid}_query.png— same bug, not flagged in theissues but fixed here for completeness
QueryImageTextRenderer.render→{example_id}_query_card.png(🔒 Path traversal vulnerability in QueryImageTextRenderer.render #79)No public signature changes; legitimate ids (no separators) are completely unaffected.
Tests
Added
tests/test_pixel_query_paths.py(runs under the existingpytest tests/CI job):_safe_stemstrips../, absolute paths, nested and Windows-style separators.output_dir.abc123→abc123_query.png) — no regression.render("../evil", ...)and asserts thefile lands inside
output_dirand no file escapes (skips cleanly where no TTF is present).All 14 tests pass;
ruff checkandruff format --checkare clean.Closes #78. Closes #79.