Skip to content

fix(graph): always sanitize bundle filename, even if it already ends in .cgc - #1541

Merged
Shashankss1205 merged 1 commit into
CodeGraphContext:mainfrom
surajthedev:fix/sanitize-bundle-filename-cgc-skip
Aug 2, 2026
Merged

Shashankss1205 merged 1 commit into
CodeGraphContext:mainfrom
surajthedev:fix/sanitize-bundle-filename-cgc-skip

Conversation

@surajthedev

Copy link
Copy Markdown
Contributor

Closes #1517

sanitize_bundle_filename in utils/path_sandbox.py only 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 .cgc only 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$.cgcwe_ird_.cgc).

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

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

@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 Shashankss1205 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@Shashankss1205
Shashankss1205 merged commit d0f85c2 into CodeGraphContext:main Aug 2, 2026
17 of 18 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Aug 2, 2026
Shashankss1205 added a commit that referenced this pull request Aug 2, 2026
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>
@Shashankss1205 Shashankss1205 added gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:clean GSSoC quality: x1.2 contributor / +5 mentor type:security GSSoC type bonus: security labels Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:clean GSSoC quality: x1.2 contributor / +5 mentor type:security GSSoC type bonus: security

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(graph): sanitize_bundle_filename skips sanitization entirely for unsafe names that already end in .cgc

3 participants