Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.
Rust ai-agentsclaude-codeclaude-code-pluginclicodexcursordevsecopsmcposvowasprustsastsecret-scanningsecretssecuritysecurity-scannersql-injectionvulnerabilityvulnerability-scannerxss
feat(sarif): give SARIF rules a full description and help with the fix (#105)
Onur Ugurfdfb5a748d9e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c520fd2..e6dcd20 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -62,6 +62,9 @@- Agent: new rule `agent.mcp-auto-approve` (high) for `"enableAllProjectMcpServers": true` in`.claude/settings*.json`, which starts every MCP server in the project's `.mcp.json` without asking abouteach one.+- CLI: SARIF rules have a `fullDescription` and a `help` text (the fix, the CWE and OWASP category, and the+ link), so a GitHub code scanning alert shows the fix in its side panel. `--list-rules --json` and the MCP+ `list_rules` tool include each rule's `fix`.## 1.0.2 (2026-11-23)diff --git a/src/lib.rs b/src/lib.rsindex e8192fb..90af4d5 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -18,19 +18,27 @@ pub struct RuleInfo {pub family: Family,pub severity: Severity,pub message: &'static str,+ pub fix: &'static str,pub cwe: &'static str,pub owasp: &'static str,pub learn_more: &'static str,}impl RuleInfo {- fn new(id: &'static str, family: Family, severity: Severity, message: &'static str) -> Self {+ fn new(+ id: &'static str,+ family: Family,+ severity: Severity,+ message: &'static str,+ fix: &'static str,+ ) -> Self {let r = refs::of(id);Self {id,family,severity,message,+ fix,cwe: r.cwe,owasp: r.owasp,learn_more: r.learn_more,@@ -42,23 +50,24 @@ pub fn rules() -> Vec<RuleInfo> {let mut seen = std::collections::HashSet::new();rules::all().filter(|r| seen.insert(r.id))- .map(|r| RuleInfo::new(r.id, r.family, r.severity, r.message))+ .map(|r| RuleInfo::new(r.id, r.family, r.severity, r.message, r.fix)).chain(rules::agent::STRUCTURED.iter()- .map(|&(id, severity, message)| {- RuleInfo::new(id, Family::Agent, severity, message)+ .map(|&(id, severity, message, fix)| {+ RuleInfo::new(id, Family::Agent, severity, message, fix)}),).chain(std::iter::once({- let (id, severity, message) = rules::secrets::ENV_NOT_IGNORED;- RuleInfo::new(id, Family::Secret, severity, message)+ let (id, severity, message, fix) = rules::secrets::ENV_NOT_IGNORED;+ RuleInfo::new(id, Family::Secret, severity, message, fix)})).chain(std::iter::once(RuleInfo::new("dependency.known-vulnerability",Family::Dependency,Severity::High,"A locked dependency version has a published advisory (OSV.dev).",+ "Upgrade the package to the fixed version the advisory names, or read the advisory for workarounds if none is published.",))).collect()}diff --git a/src/rules/agent.rs b/src/rules/agent.rsindex 4a2a562..5af26ba 100644--- a/src/rules/agent.rs+++ b/src/rules/agent.rs@@ -115,29 +115,42 @@ pub static RULES: &[Rule] = &[),];-pub static STRUCTURED: &[(&str, Severity, &str)] = &[+/// Rules found by reading the config's structure. A finding writes its own message (and, for a+/// secret in `headers`, its own fix); these are the general texts for `--list-rules` and the+/// SARIF rule help.+pub static STRUCTURED: &[(&str, Severity, &str, &str)] = &[("agent.unrestricted-shell",Severity::High,"Every shell command is pre-approved, so the agent can run anything without asking.",+ SHELL_FIX,),("agent.mcp-unpinned",Severity::Medium,"An MCP server is started from a package or image with no pinned version.",+ UNPINNED_FIX,),("agent.mcp-plaintext-secret",Severity::High,"An MCP server's token or key is written in plain text in the config.",+ PLAINTEXT_FIX,),("agent.mcp-insecure-url",Severity::High,"A remote MCP server is reached over plain HTTP.",+ INSECURE_URL_FIX,),];+const SHELL_FIX: &str = "Allow specific commands, for example \"Bash(npm test:*)\".";+const UNPINNED_FIX: &str =+ "Pin an exact version ([email protected], pkg==1.2.3, or an image digest) and update on purpose.";+const PLAINTEXT_FIX: &str = "Reference an environment variable (\"${VAR}\") and keep the value out of files that get shared or committed.";+const INSECURE_URL_FIX: &str = "Use https:// for every MCP server that is not on this machine.";+pub fn structured(file: &FileInfo, text: &Text) -> Vec<Finding> {if !is_mcp_config(file) {return Vec::new();@@ -200,7 +213,7 @@ fn check_claude_permissions(file: &FileInfo, text: &Text, json: &Value, out: &mufamily: Family::Agent,severity: Severity::High,message: "Every shell command is pre-approved, so the agent can run anything without asking.",- fix: "Allow specific commands, for example \"Bash(npm test:*)\".",+ fix: SHELL_FIX,secret: None,},));@@ -249,7 +262,7 @@ fn check_server(family: Family::Agent,severity: Severity::Medium,message: &format!("The MCP server runs `{spec}` without a pinned version, so every start installs whatever was published last."),- fix: "Pin an exact version ([email protected], pkg==1.2.3, or an image digest) and update on purpose.",+ fix: UNPINNED_FIX,secret: None,},));@@ -290,7 +303,7 @@ fn check_server(} else {(format!("The MCP server's {k} is written in plain text in the config."),- "Reference an environment variable (\"${VAR}\") and keep the value out of files that get shared or committed.",+ PLAINTEXT_FIX,)};out.push(finding(@@ -333,7 +346,7 @@ fn check_server(family: Family::Agent,severity: Severity::High,message: "A remote MCP server is reached over plain HTTP, so its tools and your data can be read or changed on the way.",- fix: "Use https:// for every MCP server that is not on this machine.",+ fix: INSECURE_URL_FIX,secret: None,},));diff --git a/src/rules/secrets.rs b/src/rules/secrets.rsindex 79b3e11..5f50773 100644--- a/src/rules/secrets.rs+++ b/src/rules/secrets.rs@@ -7,10 +7,11 @@ use crate::{Family, Finding, Severity};pub const NAME_ONLY: &[&str] = &["secret.public-env-secret"];-pub const ENV_NOT_IGNORED: (&str, Severity, &str) = (+pub const ENV_NOT_IGNORED: (&str, Severity, &str, &str) = ("secret.env-not-ignored",Severity::Medium,"The project has env files but .gitignore does not exclude .env, so real secrets are one git add away from the repository.",+ "Add .env and .env.* to .gitignore, with !.env.example so the example file stays tracked.",);pub fn is_env(name: &str) -> bool {@@ -43,7 +44,7 @@ pub fn env_not_ignored(root: &Path, env_files: &[String]) -> Option<Finding> {// copy the secret value into a diagnostic snippet.let empty = Text::new("");let finding_text = if has_gitignore { &text } else { &empty };- let (id, severity, message) = ENV_NOT_IGNORED;+ let (id, severity, message, fix) = ENV_NOT_IGNORED;Some(finding(&FileInfo::new(&file),finding_text,@@ -53,7 +54,7 @@ pub fn env_not_ignored(root: &Path, env_files: &[String]) -> Option<Finding> {family: Family::Secret,severity,message,- fix: "Add .env and .env.* to .gitignore, with !.env.example so the example file stays tracked.",+ fix,secret: None,},))diff --git a/src/sarif.rs b/src/sarif.rsindex a8bcfa5..ff3e9cf 100644--- a/src/sarif.rs+++ b/src/sarif.rs@@ -21,6 +21,21 @@ fn score(s: Severity) -> &'static str {}}+/// Fix texts are plain text; keep `*`, `_`, `<` and the like from turning into markdown or HTML.+fn escape_markdown(s: &str) -> String {+ let mut out = String::with_capacity(s.len());+ for c in s.chars() {+ if matches!(+ c,+ '\\' | '`' | '*' | '_' | '[' | ']' | '<' | '>' | '&' | '#' | '|' | '!'+ ) {+ out.push('\\');+ }+ out.push(c);+ }+ out+}+pub fn render(report: &Report) -> Value {let used: BTreeSet<&str> = report.findings.iter().map(|f| f.rule.as_str()).collect();let rules: Vec<Value> = crate::rules()@@ -31,6 +46,17 @@ pub fn render(report: &Report) -> Value {"id": r.id,"name": r.id,"shortDescription": { "text": r.message },+ "fullDescription": { "text": r.message },+ "help": {+ "text": format!(+ "Fix: {}\n\n{}, OWASP {}\n\nLearn more: {}",+ r.fix, r.cwe, r.owasp, r.learn_more+ ),+ "markdown": format!(+ "**Fix:** {}\n\n{}, OWASP {}\n\n[Learn more]({})",+ escape_markdown(r.fix), r.cwe, r.owasp, r.learn_more+ ),+ },"helpUri": r.learn_more,"defaultConfiguration": { "level": level(r.severity) },"properties": {diff --git a/tests/cli.rs b/tests/cli.rsindex 8a9dd6b..25d9692 100644--- a/tests/cli.rs+++ b/tests/cli.rs@@ -106,6 +106,7 @@ fn every_rule_has_a_cwe_and_a_reference() {.is_some_and(|u| u.starts_with("https://")),"{r}");+ assert!(r["fix"].as_str().is_some_and(|f| !f.is_empty()), "{r}");}}@@ -131,13 +132,37 @@ fn sarif_output_for_code_scanning() {.unwrap()>= 1);- assert!(- run["tool"]["driver"]["rules"]- .as_array()- .unwrap()- .iter()- .any(|d| d["id"] == r["ruleId"])- );+ let rules = run["tool"]["driver"]["rules"].as_array().unwrap();+ assert!(rules.iter().any(|d| d["id"] == r["ruleId"]));+ for d in rules {+ let text = |v: &serde_json::Value| v.as_str().filter(|s| !s.is_empty()).is_some();+ assert!(text(&d["fullDescription"]["text"]), "{d}");+ assert!(text(&d["help"]["text"]), "{d}");+ assert!(text(&d["help"]["markdown"]), "{d}");+ for field in ["text", "markdown"] {+ let help = d["help"][field].as_str().unwrap();+ assert!(help.contains("CWE-"), "{d}");+ assert!(help.contains(d["helpUri"].as_str().unwrap()), "{d}");+ }+ }+}++#[test]+fn sarif_rule_help_has_the_fix() {+ let (_, out) = run(&[&fixture("agent"), "--sarif", "--offline"]);+ let sarif: serde_json::Value = serde_json::from_str(&out).unwrap();+ let rules = sarif["runs"][0]["tool"]["driver"]["rules"]+ .as_array()+ .unwrap();+ let shell = rules+ .iter()+ .find(|d| d["id"] == "agent.unrestricted-shell")+ .expect("agent.unrestricted-shell in the agent fixture");+ let help = shell["help"]["text"].as_str().unwrap();+ assert!(help.contains("Allow specific commands"), "{shell}");+ assert!(help.contains("LLM06:2025 Excessive Agency"), "{shell}");+ let markdown = shell["help"]["markdown"].as_str().unwrap();+ assert!(markdown.contains("Bash(npm test:\\*)"), "{shell}");}#[test]