Skip to content

Commit 792191b

Browse files
committed
fix(assail): blank // comments only where // is a comment
analyze_cross_language blanked C-style `//` line comments in every file before matching URLs. In shell scripts and Justfile recipes that cut `curl http://host` at the `//`, so an unquoted plain-HTTP URL was never reported (found while testing PA1 claim (c), whose test had to quote its URL). routing.rs gains slash_line_comments(Language), an exhaustive match beside `route`, and the cross-language pass takes the file's (or the embedded script's) language. Languages whose comment syntax the table does not record (nextgen DSLs, Datalog, Unknown) keep the old blanking. Tests: claim (c) now uses an unquoted recipe URL; slash_comment_tests checks a shell script (reported) and a Rust doc comment (ignored). Planted faults "always blank" and "never blank" each fail them. Self-scan findings are unchanged (36 before and after, on main). PROOF-NEEDS closes the open recall-gap row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jma5ixtpeZyJRmfoSsC98u
1 parent f2c46ba commit 792191b

3 files changed

Lines changed: 146 additions & 23 deletions

File tree

‎PROOF-NEEDS.adoc‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ scans a Justfile and a Lua file end to end. Each test was seen to fail on
154154
a planted fault: an unrouted analyzer, Java sent to the generic analyzer,
155155
cross-language checks forced on, and the README's stale count of 49.
156156

157+
The cross-language checks blank `//` comments only in languages where `//`
158+
is a comment (`slash_line_comments`, an exhaustive table beside `route`).
159+
Blanking every file used to cut unquoted URLs in shell scripts and Justfile
160+
recipes, a recall gap found while testing (c). (c)'s test now uses an
161+
unquoted URL, and `slash_comment_tests` checks a shell script and a Rust doc
162+
comment. Blanking every language, and blanking none, were each seen to fail
163+
those tests. Languages whose comment syntax the table does not record keep
164+
the earlier blanking.
165+
157166
Routing is not coverage: `Language::Unknown` goes to `InputAdapter`, and a
158167
file there with no configuration adapter is marked `unsupported` in the
159168
coverage ledger and skipped. So (a) and (b) say which analyzer each
@@ -267,11 +276,4 @@ tests above are exhaustive over a finite enum, but they are tests, and (a)
267276
reads the source with a pattern match. (d) is a documentation check and
268277
stays a test.
269278

270-
|Unquoted `http://` URLs are missed by the cross-language check
271-
|Fix first, then test
272-
|`analyze_cross_language` strips C-style `//` comments from every file
273-
before matching, which also cuts `curl http://host` in shell. A quoted
274-
URL is found; an unquoted one in a `.sh` file or a Justfile recipe is not.
275-
This is a recall gap in the InsecureProtocol detector, found while testing
276-
PA1 (c).
277279
|===

‎src/assail/analyzer.rs‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ impl Analyzer {
822822
&script.content,
823823
&mut file_weak_points,
824824
&rel_path,
825+
script.language,
825826
)?;
826827
for finding in &mut file_weak_points[start..] {
827828
// Lines are relative to the extracted block, not the
@@ -1071,7 +1072,7 @@ impl Analyzer {
10711072
// comments or schema identifiers as executable source creates false
10721073
// findings. Source-language adapters retain their existing checks.
10731074
if super::routing::runs_cross_language(configuration.is_some()) {
1074-
self.analyze_cross_language(&content, &mut file_weak_points, &rel_path)?;
1075+
self.analyze_cross_language(&content, &mut file_weak_points, &rel_path, file_lang)?;
10751076
}
10761077

10771078
coverage.mark(file, "analyzed", None, Some(&raw_bytes));
@@ -5320,20 +5321,25 @@ impl Analyzer {
53205321
content: &str,
53215322
weak_points: &mut Vec<WeakPoint>,
53225323
file_path: &str,
5324+
lang: Language,
53235325
) -> Result<()> {
53245326
// HTTP (insecure) URLs - should be HTTPS
53255327
// Count http:// URLs that are NOT localhost/127.0.0.1 (those are fine).
53265328
//
5327-
// Strip C-family line comments first: `/// example: http://example.com`
5328-
// in a doc-comment is illustrative prose, not a configured endpoint,
5329-
// and was the source of repeated FPs on JSON-LD `@type` namespace URIs
5330-
// documented in /// blocks. The same heuristic naturally handles JS,
5331-
// Java, C, C++, Go — every language whose comment syntax is `//`.
5332-
// Python `#`, Lisp `;`, etc. are not currently de-noised; the
5333-
// cross-language detector is best-effort, and a follow-up can add
5334-
// language-aware stripping per file_path extension.
5335-
let scan_content_owned = strip_c_family_line_comments(content);
5336-
let scan_content: &str = &scan_content_owned;
5329+
// Blank `//` line comments first, but only where `//` is a comment:
5330+
// `/// example: http://example.com` in a doc comment is illustrative
5331+
// prose, not a configured endpoint, and was the source of repeated FPs
5332+
// on JSON-LD `@type` namespace URIs documented in /// blocks. In a
5333+
// shell script the same blanking would cut `curl http://host`, so
5334+
// `slash_line_comments` decides per language. Python `#`, Lisp `;`,
5335+
// etc. comments are not de-noised; this detector is best-effort.
5336+
let scan_content_owned;
5337+
let scan_content: &str = if super::routing::slash_line_comments(lang) {
5338+
scan_content_owned = strip_c_family_line_comments(content);
5339+
&scan_content_owned
5340+
} else {
5341+
content
5342+
};
53375343
let http_re = RE_HTTP_URL
53385344
.get_or_init(|| Regex::new(r#"http://[a-zA-Z0-9]"#).expect("static regex is valid"));
53395345
let http_localhost_re = RE_HTTP_LOCALHOST.get_or_init(|| {
@@ -6797,7 +6803,7 @@ mod tests {
67976803
let analyzer = Analyzer::new(std::path::Path::new(".")).expect("analyzer construction");
67986804
let mut wp = Vec::new();
67996805
analyzer
6800-
.analyze_cross_language(content, &mut wp, "fixture.rs")
6806+
.analyze_cross_language(content, &mut wp, "fixture.rs", Language::Rust)
68016807
.expect("analyze_cross_language");
68026808
wp.iter()
68036809
.filter(|w| matches!(w.category, WeakPointCategory::InsecureProtocol))

‎src/assail/routing.rs‎

Lines changed: 119 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,73 @@ pub(crate) fn route(lang: Language) -> Route {
115115
}
116116
}
117117

118+
/// Whether `//` starts a line comment in `lang`. The cross-language checks
119+
/// blank such comments before matching, so an illustrative URL in a doc
120+
/// comment is not reported. In a language where `//` is not a comment,
121+
/// blanking would cut real code, such as a `curl` of a plain-HTTP URL in a shell
122+
/// script, so those languages are matched as written.
123+
///
124+
/// Languages whose comment syntax this table does not record (the nextgen
125+
/// DSLs, Datalog, whose dialects differ, and `Unknown`) keep the earlier
126+
/// behaviour and are blanked.
127+
pub(crate) fn slash_line_comments(lang: Language) -> bool {
128+
use Language as L;
129+
match lang {
130+
L::Rust
131+
| L::C
132+
| L::Cpp
133+
| L::Go
134+
| L::Java
135+
| L::JavaScript
136+
| L::Php
137+
| L::Gleam
138+
| L::ReScript
139+
| L::Zig
140+
| L::Odin
141+
| L::Pony
142+
| L::DLang
143+
| L::Chapel => true,
144+
L::Python
145+
| L::Ruby
146+
| L::Elixir
147+
| L::Erlang
148+
| L::OCaml
149+
| L::StandardML
150+
| L::Scheme
151+
| L::Racket
152+
| L::Haskell
153+
| L::PureScript
154+
| L::Idris
155+
| L::Lean
156+
| L::Agda
157+
| L::Isabelle
158+
| L::Coq
159+
| L::Prolog
160+
| L::Logtalk
161+
| L::Ada
162+
| L::Nim
163+
| L::Nickel
164+
| L::Nix
165+
| L::Shell
166+
| L::Julia
167+
| L::Lua => false,
168+
L::Datalog
169+
| L::WokeLang
170+
| L::Eclexia
171+
| L::MyLang
172+
| L::JuliaTheViper
173+
| L::Oblibeny
174+
| L::Anvomidav
175+
| L::AffineScript
176+
| L::Ephapax
177+
| L::BetLang
178+
| L::ErrorLang
179+
| L::VCL
180+
| L::FBQL
181+
| L::Unknown => true,
182+
}
183+
}
184+
118185
impl Route {
119186
/// The function that `analyze_inner` calls for this route.
120187
#[cfg_attr(not(test), allow(dead_code))]
@@ -275,13 +342,11 @@ mod tests {
275342
let url = |path: &str| format!("{}://example.org/{path}", "http");
276343
let tmp = TempDir::new().unwrap();
277344
// A Justfile is configuration. Its variable is configuration content;
278-
// its recipe body is an embedded shell script. The recipe URL is
279-
// quoted: the cross-language detector strips `//` comments first,
280-
// which also cuts an unquoted URL (a separate recall gap).
345+
// its recipe body is an embedded shell script, with an unquoted URL.
281346
fs::write(
282347
tmp.path().join("Justfile"),
283348
format!(
284-
"mirror := \"{}\"\n\nfetch:\n curl \"{}\"\n",
349+
"mirror := \"{}\"\n\nfetch:\n curl {}\n",
285350
url("variable"),
286351
url("recipe")
287352
),
@@ -348,3 +413,53 @@ mod tests {
348413
}
349414
}
350415
}
416+
417+
#[cfg(test)]
418+
mod slash_comment_tests {
419+
use super::slash_line_comments;
420+
use crate::assail::Analyzer;
421+
use crate::types::{Language, WeakPointCategory};
422+
use std::fs;
423+
use tempfile::TempDir;
424+
425+
fn insecure_in(file: &str, content: &str) -> usize {
426+
let tmp = TempDir::new().unwrap();
427+
fs::write(tmp.path().join(file), content).unwrap();
428+
Analyzer::new(tmp.path())
429+
.unwrap()
430+
.analyze()
431+
.unwrap()
432+
.weak_points
433+
.iter()
434+
.filter(|w| w.category == WeakPointCategory::InsecureProtocol)
435+
.count()
436+
}
437+
438+
#[test]
439+
fn languages_without_slash_comments_are_matched_as_written() {
440+
for lang in [Language::Shell, Language::Python, Language::Lua] {
441+
assert!(!slash_line_comments(lang), "{lang:?}");
442+
}
443+
for lang in [Language::Rust, Language::JavaScript, Language::Go] {
444+
assert!(slash_line_comments(lang), "{lang:?}");
445+
}
446+
}
447+
448+
/// The recall gap this table closes: an unquoted URL in a shell script
449+
/// used to be cut at `//` before matching.
450+
#[test]
451+
fn an_unquoted_url_in_a_shell_script_is_reported() {
452+
let url = format!("{}://example.org/archive.tar", "http");
453+
assert_eq!(insecure_in("fetch.sh", &format!("curl -O {url}\n")), 1);
454+
}
455+
456+
/// The precision the blanking exists for is kept where `//` is a comment.
457+
#[test]
458+
fn a_url_in_a_rust_doc_comment_is_still_ignored() {
459+
let url = format!("{}://example.org/spec", "http");
460+
assert_eq!(
461+
insecure_in("lib.rs", &format!("/// See {url}\npub fn f() {{}}\n")),
462+
0
463+
);
464+
}
465+
}

0 commit comments

Comments
 (0)