Skip to content

fix(eval): sanitize example_id to prevent path traversal (fixes #78, #79)#80

Open
dex0shubham wants to merge 1 commit into
StarTrail-org:mainfrom
dex0shubham:fix/eval-path-traversal
Open

fix(eval): sanitize example_id to prevent path traversal (fixes #78, #79)#80
dex0shubham wants to merge 1 commit into
StarTrail-org:mainfrom
dex0shubham:fix/eval-path-traversal

Conversation

@dex0shubham

Copy link
Copy Markdown
Contributor

Problem

example_id is interpolated straight into output filenames via os.path.join in
eval/lib/pixel_query.py, with no sanitization. An id containing path separators
(e.g. ../../evil) makes the renderer write files outside the intended
output_dir — a path-traversal write. example_id comes 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 path
component — never a separator, never absolute) and applied it at all three affected
sites:

No public signature changes; legitimate ids (no separators) are completely unaffected.

Tests

Added tests/test_pixel_query_paths.py (runs under the existing pytest tests/ CI job):

  • _safe_stem strips ../, absolute paths, nested and Windows-style separators.
  • Constructed output paths for a battery of malicious ids resolve inside output_dir.
  • Normal ids are preserved (abc123abc123_query.png) — no regression.
  • A font-guarded integration test actually calls render("../evil", ...) and asserts the
    file lands inside output_dir and no file escapes (skips cleanly where no TTF is present).

All 14 tests pass; ruff check and ruff format --check are clean.

Closes #78. Closes #79.

…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>
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🔒 Path traversal vulnerability in QueryImageTextRenderer.render 🔒 Path traversal vulnerability in output file path

1 participant