From 792191bd7ba0e311a10c24c22b92f6b7f73681ba Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 16:24:36 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Jma5ixtpeZyJRmfoSsC98u --- PROOF-NEEDS.adoc | 16 +++--- src/assail/analyzer.rs | 30 ++++++---- src/assail/routing.rs | 123 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 146 insertions(+), 23 deletions(-) diff --git a/PROOF-NEEDS.adoc b/PROOF-NEEDS.adoc index f1b1abd..34317af 100644 --- a/PROOF-NEEDS.adoc +++ b/PROOF-NEEDS.adoc @@ -154,6 +154,15 @@ scans a Justfile and a Lua file end to end. Each test was seen to fail on a planted fault: an unrouted analyzer, Java sent to the generic analyzer, cross-language checks forced on, and the README's stale count of 49. +The cross-language checks blank `//` comments only in languages where `//` +is a comment (`slash_line_comments`, an exhaustive table beside `route`). +Blanking every file used to cut unquoted URLs in shell scripts and Justfile +recipes, a recall gap found while testing (c). (c)'s test now uses an +unquoted URL, and `slash_comment_tests` checks a shell script and a Rust doc +comment. Blanking every language, and blanking none, were each seen to fail +those tests. Languages whose comment syntax the table does not record keep +the earlier blanking. + Routing is not coverage: `Language::Unknown` goes to `InputAdapter`, and a file there with no configuration adapter is marked `unsupported` in the 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) reads the source with a pattern match. (d) is a documentation check and stays a test. -|Unquoted `http://` URLs are missed by the cross-language check -|Fix first, then test -|`analyze_cross_language` strips C-style `//` comments from every file -before matching, which also cuts `curl http://host` in shell. A quoted -URL is found; an unquoted one in a `.sh` file or a Justfile recipe is not. -This is a recall gap in the InsecureProtocol detector, found while testing -PA1 (c). |=== diff --git a/src/assail/analyzer.rs b/src/assail/analyzer.rs index d375d0c..30c150c 100644 --- a/src/assail/analyzer.rs +++ b/src/assail/analyzer.rs @@ -822,6 +822,7 @@ impl Analyzer { &script.content, &mut file_weak_points, &rel_path, + script.language, )?; for finding in &mut file_weak_points[start..] { // Lines are relative to the extracted block, not the @@ -1071,7 +1072,7 @@ impl Analyzer { // comments or schema identifiers as executable source creates false // findings. Source-language adapters retain their existing checks. if super::routing::runs_cross_language(configuration.is_some()) { - self.analyze_cross_language(&content, &mut file_weak_points, &rel_path)?; + self.analyze_cross_language(&content, &mut file_weak_points, &rel_path, file_lang)?; } coverage.mark(file, "analyzed", None, Some(&raw_bytes)); @@ -5320,20 +5321,25 @@ impl Analyzer { content: &str, weak_points: &mut Vec, file_path: &str, + lang: Language, ) -> Result<()> { // HTTP (insecure) URLs - should be HTTPS // Count http:// URLs that are NOT localhost/127.0.0.1 (those are fine). // - // Strip C-family line comments first: `/// example: http://example.com` - // in a doc-comment is illustrative prose, not a configured endpoint, - // and was the source of repeated FPs on JSON-LD `@type` namespace URIs - // documented in /// blocks. The same heuristic naturally handles JS, - // Java, C, C++, Go — every language whose comment syntax is `//`. - // Python `#`, Lisp `;`, etc. are not currently de-noised; the - // cross-language detector is best-effort, and a follow-up can add - // language-aware stripping per file_path extension. - let scan_content_owned = strip_c_family_line_comments(content); - let scan_content: &str = &scan_content_owned; + // Blank `//` line comments first, but only where `//` is a comment: + // `/// example: http://example.com` in a doc comment is illustrative + // prose, not a configured endpoint, and was the source of repeated FPs + // on JSON-LD `@type` namespace URIs documented in /// blocks. In a + // shell script the same blanking would cut `curl http://host`, so + // `slash_line_comments` decides per language. Python `#`, Lisp `;`, + // etc. comments are not de-noised; this detector is best-effort. + let scan_content_owned; + let scan_content: &str = if super::routing::slash_line_comments(lang) { + scan_content_owned = strip_c_family_line_comments(content); + &scan_content_owned + } else { + content + }; let http_re = RE_HTTP_URL .get_or_init(|| Regex::new(r#"http://[a-zA-Z0-9]"#).expect("static regex is valid")); let http_localhost_re = RE_HTTP_LOCALHOST.get_or_init(|| { @@ -6797,7 +6803,7 @@ mod tests { let analyzer = Analyzer::new(std::path::Path::new(".")).expect("analyzer construction"); let mut wp = Vec::new(); analyzer - .analyze_cross_language(content, &mut wp, "fixture.rs") + .analyze_cross_language(content, &mut wp, "fixture.rs", Language::Rust) .expect("analyze_cross_language"); wp.iter() .filter(|w| matches!(w.category, WeakPointCategory::InsecureProtocol)) diff --git a/src/assail/routing.rs b/src/assail/routing.rs index aa19d80..a2d1f0b 100644 --- a/src/assail/routing.rs +++ b/src/assail/routing.rs @@ -115,6 +115,73 @@ pub(crate) fn route(lang: Language) -> Route { } } +/// Whether `//` starts a line comment in `lang`. The cross-language checks +/// blank such comments before matching, so an illustrative URL in a doc +/// comment is not reported. In a language where `//` is not a comment, +/// blanking would cut real code, such as a `curl` of a plain-HTTP URL in a shell +/// script, so those languages are matched as written. +/// +/// Languages whose comment syntax this table does not record (the nextgen +/// DSLs, Datalog, whose dialects differ, and `Unknown`) keep the earlier +/// behaviour and are blanked. +pub(crate) fn slash_line_comments(lang: Language) -> bool { + use Language as L; + match lang { + L::Rust + | L::C + | L::Cpp + | L::Go + | L::Java + | L::JavaScript + | L::Php + | L::Gleam + | L::ReScript + | L::Zig + | L::Odin + | L::Pony + | L::DLang + | L::Chapel => true, + L::Python + | L::Ruby + | L::Elixir + | L::Erlang + | L::OCaml + | L::StandardML + | L::Scheme + | L::Racket + | L::Haskell + | L::PureScript + | L::Idris + | L::Lean + | L::Agda + | L::Isabelle + | L::Coq + | L::Prolog + | L::Logtalk + | L::Ada + | L::Nim + | L::Nickel + | L::Nix + | L::Shell + | L::Julia + | L::Lua => false, + L::Datalog + | L::WokeLang + | L::Eclexia + | L::MyLang + | L::JuliaTheViper + | L::Oblibeny + | L::Anvomidav + | L::AffineScript + | L::Ephapax + | L::BetLang + | L::ErrorLang + | L::VCL + | L::FBQL + | L::Unknown => true, + } +} + impl Route { /// The function that `analyze_inner` calls for this route. #[cfg_attr(not(test), allow(dead_code))] @@ -275,13 +342,11 @@ mod tests { let url = |path: &str| format!("{}://example.org/{path}", "http"); let tmp = TempDir::new().unwrap(); // A Justfile is configuration. Its variable is configuration content; - // its recipe body is an embedded shell script. The recipe URL is - // quoted: the cross-language detector strips `//` comments first, - // which also cuts an unquoted URL (a separate recall gap). + // its recipe body is an embedded shell script, with an unquoted URL. fs::write( tmp.path().join("Justfile"), format!( - "mirror := \"{}\"\n\nfetch:\n curl \"{}\"\n", + "mirror := \"{}\"\n\nfetch:\n curl {}\n", url("variable"), url("recipe") ), @@ -348,3 +413,53 @@ mod tests { } } } + +#[cfg(test)] +mod slash_comment_tests { + use super::slash_line_comments; + use crate::assail::Analyzer; + use crate::types::{Language, WeakPointCategory}; + use std::fs; + use tempfile::TempDir; + + fn insecure_in(file: &str, content: &str) -> usize { + let tmp = TempDir::new().unwrap(); + fs::write(tmp.path().join(file), content).unwrap(); + Analyzer::new(tmp.path()) + .unwrap() + .analyze() + .unwrap() + .weak_points + .iter() + .filter(|w| w.category == WeakPointCategory::InsecureProtocol) + .count() + } + + #[test] + fn languages_without_slash_comments_are_matched_as_written() { + for lang in [Language::Shell, Language::Python, Language::Lua] { + assert!(!slash_line_comments(lang), "{lang:?}"); + } + for lang in [Language::Rust, Language::JavaScript, Language::Go] { + assert!(slash_line_comments(lang), "{lang:?}"); + } + } + + /// The recall gap this table closes: an unquoted URL in a shell script + /// used to be cut at `//` before matching. + #[test] + fn an_unquoted_url_in_a_shell_script_is_reported() { + let url = format!("{}://example.org/archive.tar", "http"); + assert_eq!(insecure_in("fetch.sh", &format!("curl -O {url}\n")), 1); + } + + /// The precision the blanking exists for is kept where `//` is a comment. + #[test] + fn a_url_in_a_rust_doc_comment_is_still_ignored() { + let url = format!("{}://example.org/spec", "http"); + assert_eq!( + insecure_in("lib.rs", &format!("/// See {url}\npub fn f() {{}}\n")), + 0 + ); + } +}