2026-02-25 21:16:36 -05:00
|
|
|
use crate::evidence::Confidence;
|
|
|
|
|
use crate::patterns::{Pattern, PatternCategory, PatternTier, Severity};
|
2025-06-17 01:17:48 +02:00
|
|
|
|
2026-02-25 21:16:36 -05:00
|
|
|
/// Go AST patterns.
|
|
|
|
|
///
|
|
|
|
|
/// Taint rules cover `exec.Command` (command injection), `db.Query`/`db.Exec`
|
|
|
|
|
/// (SQL sinks). AST patterns here focus on **TLS misconfiguration**,
|
|
|
|
|
/// **weak crypto**, **unsafe.Pointer**, and **hardcoded secrets**.
|
2025-06-17 01:17:48 +02:00
|
|
|
pub const PATTERNS: &[Pattern] = &[
|
2026-02-25 21:16:36 -05:00
|
|
|
// ── Tier A: Command execution ──────────────────────────────────────
|
2025-06-24 20:27:06 +02:00
|
|
|
Pattern {
|
2026-02-25 21:16:36 -05:00
|
|
|
id: "go.cmdi.exec_command",
|
2026-04-29 00:58:38 -04:00
|
|
|
description: "exec.Command() runs an arbitrary process",
|
2026-02-25 21:16:36 -05:00
|
|
|
query: r#"(call_expression
|
|
|
|
|
function: (selector_expression
|
|
|
|
|
field: (field_identifier) @f (#eq? @f "Command")))
|
|
|
|
|
@vuln"#,
|
|
|
|
|
severity: Severity::High,
|
|
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::CommandExec,
|
|
|
|
|
confidence: Confidence::High,
|
|
|
|
|
},
|
|
|
|
|
// ── Tier A: Unsafe pointer ─────────────────────────────────────────
|
|
|
|
|
Pattern {
|
|
|
|
|
id: "go.memory.unsafe_pointer",
|
2026-04-29 00:58:38 -04:00
|
|
|
description: "unsafe.Pointer bypasses the Go type system",
|
2026-02-25 21:16:36 -05:00
|
|
|
query: r#"(call_expression
|
|
|
|
|
function: (selector_expression
|
|
|
|
|
operand: (identifier) @pkg (#eq? @pkg "unsafe")
|
|
|
|
|
field: (field_identifier) @f (#eq? @f "Pointer")))
|
|
|
|
|
@vuln"#,
|
2025-06-24 20:27:06 +02:00
|
|
|
severity: Severity::Medium,
|
2026-02-25 21:16:36 -05:00
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::MemorySafety,
|
|
|
|
|
confidence: Confidence::High,
|
2025-06-24 20:27:06 +02:00
|
|
|
},
|
2026-02-25 21:16:36 -05:00
|
|
|
// ── Tier A: TLS misconfiguration ───────────────────────────────────
|
2025-06-24 20:27:06 +02:00
|
|
|
Pattern {
|
2026-02-25 21:16:36 -05:00
|
|
|
id: "go.transport.insecure_skip_verify",
|
2026-04-29 00:58:38 -04:00
|
|
|
description: "InsecureSkipVerify: true disables TLS certificate validation",
|
2026-02-25 21:16:36 -05:00
|
|
|
query: r#"(keyed_element
|
|
|
|
|
(literal_element
|
|
|
|
|
(identifier) @k (#eq? @k "InsecureSkipVerify"))
|
|
|
|
|
(literal_element (true)))
|
|
|
|
|
@vuln"#,
|
2025-06-24 20:27:06 +02:00
|
|
|
severity: Severity::High,
|
2026-02-25 21:16:36 -05:00
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::InsecureTransport,
|
|
|
|
|
confidence: Confidence::High,
|
2025-06-24 20:27:06 +02:00
|
|
|
},
|
2026-02-25 21:16:36 -05:00
|
|
|
// ── Tier A: Weak crypto ────────────────────────────────────────────
|
2025-06-24 20:27:06 +02:00
|
|
|
Pattern {
|
2026-02-25 21:16:36 -05:00
|
|
|
id: "go.crypto.md5",
|
2026-04-29 00:58:38 -04:00
|
|
|
description: "md5.New() / md5.Sum() use a weak hash algorithm",
|
2026-02-25 21:16:36 -05:00
|
|
|
query: r#"(call_expression
|
|
|
|
|
function: (selector_expression
|
|
|
|
|
operand: (identifier) @pkg (#eq? @pkg "md5")))
|
|
|
|
|
@vuln"#,
|
|
|
|
|
severity: Severity::Low,
|
|
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::Crypto,
|
|
|
|
|
confidence: Confidence::Medium,
|
2025-06-24 20:27:06 +02:00
|
|
|
},
|
|
|
|
|
Pattern {
|
2026-02-25 21:16:36 -05:00
|
|
|
id: "go.crypto.sha1",
|
2026-04-29 00:58:38 -04:00
|
|
|
description: "sha1.New() / sha1.Sum() use a weak hash algorithm",
|
2026-02-25 21:16:36 -05:00
|
|
|
query: r#"(call_expression
|
|
|
|
|
function: (selector_expression
|
|
|
|
|
operand: (identifier) @pkg (#eq? @pkg "sha1")))
|
|
|
|
|
@vuln"#,
|
|
|
|
|
severity: Severity::Low,
|
|
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::Crypto,
|
|
|
|
|
confidence: Confidence::Medium,
|
|
|
|
|
},
|
|
|
|
|
// ── Tier B: SQL injection (concatenation heuristic) ────────────────
|
|
|
|
|
Pattern {
|
|
|
|
|
id: "go.sqli.query_concat",
|
|
|
|
|
description: "db.Query/Exec with concatenated string argument",
|
|
|
|
|
query: r#"(call_expression
|
|
|
|
|
function: (selector_expression
|
|
|
|
|
field: (field_identifier) @f (#match? @f "^(Query|Exec|QueryRow)$"))
|
|
|
|
|
arguments: (argument_list
|
|
|
|
|
(binary_expression) @concat))
|
|
|
|
|
@vuln"#,
|
2025-06-24 20:27:06 +02:00
|
|
|
severity: Severity::Medium,
|
2026-02-25 21:16:36 -05:00
|
|
|
tier: PatternTier::B,
|
|
|
|
|
category: PatternCategory::SqlInjection,
|
|
|
|
|
confidence: Confidence::Medium,
|
2025-06-24 20:27:06 +02:00
|
|
|
},
|
2026-02-25 21:16:36 -05:00
|
|
|
// ── Tier A: Hardcoded secrets ──────────────────────────────────────
|
2025-06-24 20:27:06 +02:00
|
|
|
Pattern {
|
2026-02-25 21:16:36 -05:00
|
|
|
id: "go.secrets.hardcoded_key",
|
|
|
|
|
description: "Variable with secret-like name assigned a string literal",
|
|
|
|
|
query: r#"(short_var_declaration
|
|
|
|
|
left: (expression_list
|
|
|
|
|
(identifier) @name (#match? @name "(?i)(password|secret|api_?key|token|private_?key)"))
|
|
|
|
|
right: (expression_list
|
|
|
|
|
(interpreted_string_literal) @val))
|
|
|
|
|
@vuln"#,
|
|
|
|
|
severity: Severity::Medium,
|
|
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::Secrets,
|
|
|
|
|
confidence: Confidence::High,
|
|
|
|
|
},
|
|
|
|
|
// ── Tier A: Deserialization ────────────────────────────────────────
|
|
|
|
|
Pattern {
|
|
|
|
|
id: "go.deser.gob_decode",
|
2026-04-29 00:58:38 -04:00
|
|
|
description: "gob.NewDecoder performs Go binary deserialization",
|
2026-02-25 21:16:36 -05:00
|
|
|
query: r#"(call_expression
|
|
|
|
|
function: (selector_expression
|
|
|
|
|
operand: (identifier) @pkg (#eq? @pkg "gob")
|
|
|
|
|
field: (field_identifier) @f (#eq? @f "NewDecoder")))
|
|
|
|
|
@vuln"#,
|
|
|
|
|
severity: Severity::Medium,
|
|
|
|
|
tier: PatternTier::A,
|
|
|
|
|
category: PatternCategory::Deserialization,
|
|
|
|
|
confidence: Confidence::High,
|
2025-06-24 20:27:06 +02:00
|
|
|
},
|
2025-06-17 01:17:48 +02:00
|
|
|
];
|