fix(graph): always sanitize bundle filename, even if it already ends in .cgc - #1541
Conversation
…nsion Previously sanitize_bundle_filename skipped the regex substitution when the filename already ended with .cgc. This allowed unsafe characters (spaces, $, parentheses, injection payloads) to pass through unmodified, creating a security-adjacent bypass. Fix: strip the .cgc extension first, run re.sub on the bare stem unconditionally, then re-attach the extension. The early guard for path-traversal sequences (/, .., backslash) is kept as-is. Added parametrized tests covering: - clean name passthrough (ok.cgc) - unsafe chars + .cgc suffix (was the bug) - unsafe chars + non-.cgc extension (existing correct behaviour) - slash-containing payload caught by early guard - slash-free unsafe payload sanitized by regex
|
@suraj-k-umar is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
Shashankss1205
left a comment
There was a problem hiding this comment.
Verified locally: trial-merged onto main with #1539 and #1540 — full suite green (1063 passed, 7 skipped).
Correct fix for #1517. Sanitizing the stem unconditionally and re-attaching the extension is the right shape — it removes the inconsistency where we ird$.txt was sanitized but we ird$.cgc was not.
I checked the traversal path specifically, since the restructure sits right below it: ../../etc/passwd.cgc still returns bundle.cgc because the ".." in filename or "/" in filename guard at the top of the function short-circuits before this code runs. The existing traversal test covers it, and it passes.
Using name.lower().endswith(".cgc") for the strip also correctly handles FOO.CGC. Thanks!
Bug-fix release. Since 0.5.4 on PyPI: - fix(indexer): record non-code files on the SCIP path so `cgc index` stops reporting a partial index forever (#1565, #1566) - fix(parsers): capture PHP imports rather than trait uses (#1522, #1563) - fix(parsers): recover Python annotated parameters — 40.3% of parameters were being dropped — and Go grouped imports (#1520, #1521, #1561) - fix(graph): always sanitize bundle filenames (#1517, #1541) - fix(cli/mcp): read import aliases from the IMPORTS relationship (#1515, #1540) - fix(cli/mcp): fall back to JSON when GCF encoding fails (#1518, #1539) Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Closes #1517
sanitize_bundle_filenameinutils/path_sandbox.pyonly ran the sanitization regex when the name did NOT already end in.cgc. This meant a name that was already unsafe but happened to end in.cgc(e.g. containing spaces,$, or control characters) skipped sanitization entirely and was returned raw.This PR makes sanitization run unconditionally on the stem, then appends
.cgconly if it's missing — so the function always returns a sanitized name regardless of the input's extension.Added a test covering an unsafe name that already ends in
.cgc(e.g.we ird$.cgc→we_ird_.cgc).