Commit fecb4ff
fix(assail): strip C-family line comments before cross-language URL detection
Self-scan repro: a doc-comment line like
/// types: ["http://hyperpolymath.dev/panic-attack/AssailReport"]
was flagging InsecureProtocol PA-IP. The string in the comment is an
illustrative JSON-LD `@type` namespace URI, not a configured endpoint —
it has no runtime effect, but the cross-language detector's regex
matched it anyway because `analyze_cross_language` was being passed
the raw file content (no comment stripping).
Fix: new `strip_c_family_line_comments` helper, applied to the content
before the http://-URL regex runs in `analyze_cross_language`. The
helper detects `//` (and `///`, `//!` by extension), respects string
literals (so `"http://localhost"` is preserved), and handles escape
sequences inside strings.
Naturally covers Rust, JavaScript, TypeScript, Java, C, C++, Go — every
language whose comment syntax is `//`. Python `#`, Lisp `;`, Lua/Idris
`--` etc. are not (yet) language-aware; the cross-language detector
remains best-effort and could be extended per file_path extension in a
follow-up.
Limits:
- Block comments (/* */) and raw-string literals (r#"..."#) are not
consumed here. The detector's existing localhost exemption + this
line-comment strip handle the bulk of FPs in practice.
- A real string-literal URL like `"http://example.com"` is STILL
flagged — the regex sees through the string. That's correct: a
hardcoded HTTP endpoint in production code is the signal we want.
- JSON-LD `@type` URIs that genuinely live in code (not in comments)
remain a TP from the regex's perspective; suppress them via the
user-classification registry if they're audited.
Regression coverage: 6 new tests in `assail::analyzer::tests` covering
basic `//`, doc-comments, string-literal preservation, escape
sequences, and the self-scan repro patterns (doc-URL stripped /
JSON-LD-string preserved).
Test URLs use http://localhost so panic-attack scanning its own
source under self-scan doesn't trip the InsecureProtocol detector on
the test data.
Verification:
- cargo test --bin panic-attack --features signing,http — 242 passed
(was 236; +6 new tests, no failures)
- cargo clippy --all-targets --features signing,http -D warnings — clean
- cargo fmt --check — clean
- self-scan before: 2 InsecureProtocol findings in storage/mod.rs
(1 doc-comment FP, 1 JSON-LD literal — out of scope)
- self-scan after: 1 InsecureProtocol finding in storage/mod.rs
(the JSON-LD literal remains; the doc-comment FP is gone)
- self-scan total findings: 11 (down from 12 yesterday; was already 11
after #51, this PR preserves the count while fixing a categorical
FP class)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0f6ea94 commit fecb4ff
1 file changed
Lines changed: 132 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4729 | 4729 | | |
4730 | 4730 | | |
4731 | 4731 | | |
4732 | | - | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
4733 | 4744 | | |
4734 | 4745 | | |
4735 | 4746 | | |
4736 | 4747 | | |
4737 | 4748 | | |
4738 | 4749 | | |
4739 | | - | |
4740 | | - | |
| 4750 | + | |
| 4751 | + | |
4741 | 4752 | | |
4742 | 4753 | | |
4743 | 4754 | | |
| |||
5531 | 5542 | | |
5532 | 5543 | | |
5533 | 5544 | | |
| 5545 | + | |
| 5546 | + | |
| 5547 | + | |
| 5548 | + | |
| 5549 | + | |
| 5550 | + | |
| 5551 | + | |
| 5552 | + | |
| 5553 | + | |
| 5554 | + | |
| 5555 | + | |
| 5556 | + | |
| 5557 | + | |
| 5558 | + | |
| 5559 | + | |
| 5560 | + | |
| 5561 | + | |
| 5562 | + | |
| 5563 | + | |
| 5564 | + | |
| 5565 | + | |
| 5566 | + | |
| 5567 | + | |
| 5568 | + | |
| 5569 | + | |
| 5570 | + | |
| 5571 | + | |
| 5572 | + | |
| 5573 | + | |
| 5574 | + | |
| 5575 | + | |
| 5576 | + | |
| 5577 | + | |
| 5578 | + | |
| 5579 | + | |
| 5580 | + | |
| 5581 | + | |
| 5582 | + | |
| 5583 | + | |
| 5584 | + | |
| 5585 | + | |
| 5586 | + | |
| 5587 | + | |
| 5588 | + | |
| 5589 | + | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
| 5595 | + | |
5534 | 5596 | | |
5535 | 5597 | | |
5536 | 5598 | | |
| |||
5869 | 5931 | | |
5870 | 5932 | | |
5871 | 5933 | | |
| 5934 | + | |
| 5935 | + | |
| 5936 | + | |
| 5937 | + | |
| 5938 | + | |
| 5939 | + | |
| 5940 | + | |
| 5941 | + | |
| 5942 | + | |
| 5943 | + | |
| 5944 | + | |
| 5945 | + | |
| 5946 | + | |
| 5947 | + | |
| 5948 | + | |
| 5949 | + | |
| 5950 | + | |
| 5951 | + | |
| 5952 | + | |
| 5953 | + | |
| 5954 | + | |
| 5955 | + | |
| 5956 | + | |
| 5957 | + | |
| 5958 | + | |
| 5959 | + | |
| 5960 | + | |
| 5961 | + | |
| 5962 | + | |
| 5963 | + | |
| 5964 | + | |
| 5965 | + | |
| 5966 | + | |
| 5967 | + | |
| 5968 | + | |
| 5969 | + | |
| 5970 | + | |
| 5971 | + | |
| 5972 | + | |
| 5973 | + | |
| 5974 | + | |
| 5975 | + | |
| 5976 | + | |
| 5977 | + | |
| 5978 | + | |
| 5979 | + | |
| 5980 | + | |
| 5981 | + | |
| 5982 | + | |
| 5983 | + | |
| 5984 | + | |
| 5985 | + | |
| 5986 | + | |
| 5987 | + | |
| 5988 | + | |
| 5989 | + | |
| 5990 | + | |
| 5991 | + | |
| 5992 | + | |
| 5993 | + | |
| 5994 | + | |
| 5995 | + | |
| 5996 | + | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
| 6000 | + | |
5872 | 6001 | | |
5873 | 6002 | | |
5874 | 6003 | | |
| |||
0 commit comments