Commit 434d640
fix(assail): strip C-family line comments before cross-lang URL detection (#52)
## Summary
Self-scan repro: a doc-comment line like
```rust
/// 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**)
- 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; cross-language remains
best-effort and could be extended per file_path extension in a
follow-up.
## Out of scope
- **Block comments (`/* */`)** and **raw-string literals
(`r#\"...\"#`)** are not consumed here. The 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 via the
user-classification registry if audited.
## Regression coverage
6 new tests in `assail::analyzer::tests`:
| Test | Asserts |
|---|---|
| `strip_c_family_line_comment_handles_basic_double_slash` | Trailing
`//` comment is dropped |
| `strip_c_family_line_comment_handles_doc_comments` | `///` and `//!`
lines are dropped |
| `strip_c_family_line_comment_preserves_urls_in_strings` |
`\"http://localhost/path\"` survives intact |
| `strip_c_family_line_comment_handles_escaped_quote_in_string` |
`\\\"hi\\\"` doesn't confuse the string tracker |
| `strip_c_family_line_comments_doc_comment_url_fp_gone` | Self-scan
repro: doc-URL → stripped |
| `strip_c_family_line_comments_keeps_jsonld_type_string` | Self-scan
companion: JSON-LD string-literal URL → preserved (out of scope, but the
stripper must not over-fire) |
**Note**: test URLs use `http://localhost` so panic-attack scanning its
own source doesn't trip the InsecureProtocol detector on the test data
itself. Same exemption rule used in production.
## Verification
- [x] `cargo test --bin panic-attack --features signing,http` — **242
passed** (was 236; +6 new tests)
- [x] `cargo clippy --all-targets --features signing,http -- -D
warnings` — clean
- [x] `cargo fmt --check` — clean
- [x] **Self-scan before**: 2 InsecureProtocol findings in
`storage/mod.rs` (1 doc-comment FP, 1 JSON-LD literal — out of scope)
- [x] **Self-scan after**: 1 InsecureProtocol finding in
`storage/mod.rs` (the JSON-LD literal remains; the doc-comment FP is
gone)
- [x] No new findings introduced anywhere
- [x] GPG-signed commit
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent bcd1903 commit 434d640
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 | | |
| |||
5880 | 5942 | | |
5881 | 5943 | | |
5882 | 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 | + | |
| 6001 | + | |
| 6002 | + | |
| 6003 | + | |
| 6004 | + | |
| 6005 | + | |
| 6006 | + | |
| 6007 | + | |
| 6008 | + | |
| 6009 | + | |
| 6010 | + | |
| 6011 | + | |
5883 | 6012 | | |
5884 | 6013 | | |
5885 | 6014 | | |
| |||
0 commit comments