File: internal/engine/pattern/matcher.goThe Pattern Matcher is the workhorse of Aguara’s detection engine. It applies 177 compiled YAML rules using regex and substring matching.
Rules can use either regex (RE2 syntax) or case-insensitive substring matching:
internal/engine/pattern/matcher.go:175-208
func matchPattern(pat rules.CompiledPattern, content string, lines []string) []matchHit { var hits []matchHit switch pat.Type { case rules.PatternRegex: if pat.Regex == nil { return nil } locs := pat.Regex.FindAllStringIndex(content, -1) for _, loc := range locs { line := lineNumberAtOffset(content, loc[0]) matched := content[loc[0]:loc[1]] if len(matched) > 200 { matched = matched[:200] + "..." } hits = append(hits, matchHit{line: line, text: matched}) } case rules.PatternContains: lower := strings.ToLower(content) target := pat.Value // already lowercased during compilation idx := 0 for { pos := strings.Index(lower[idx:], target) if pos == -1 { break } absPos := idx + pos line := lineNumberAtOffset(content, absPos) matched := content[absPos : absPos+len(target)] hits = append(hits, matchHit{line: line, text: matched}) idx = absPos + len(target) } } return hits}
Base64 and Hex Decoder
Layer 1 includes a sub-layer that decodes base64 and hex blobs, then re-scans the decoded content:
internal/engine/pattern/decoder.go:27-56
func DecodeAndRescan(target *scanner.Target, compiled []*rules.CompiledRule, cbMap []bool) []scanner.Finding { var findings []scanner.Finding content := string(target.Content) lines := target.Lines() // Scan for base64 blobs for _, loc := range base64Re.FindAllStringIndex(content, -1) { if loc[1]-loc[0] > maxEncodedBlobSize { continue } encoded := content[loc[0]:loc[1]] decoded, err := base64.StdEncoding.DecodeString(encoded) if err != nil { // try URL-safe decoded, err = base64.URLEncoding.DecodeString(encoded) if err != nil { continue } } if !isPrintable(decoded) || len(decoded) < 8 { continue } if len(decoded) > maxDecodedSize { decoded = decoded[:maxDecodedSize] } line := lineNumberAtOffset(content, loc[0]) findings = append(findings, rescan(decoded, line, lines, target, compiled, "base64", cbMap)...) } // ... similar logic for hex blobs ...}
This catches obfuscated credentials and commands hidden in base64/hex strings.
Code Block Awareness
For markdown files, Layer 1 builds a boolean map indicating which lines are inside fenced code blocks:
internal/engine/pattern/matcher.go:258-277
func BuildCodeBlockMap(lines []string) []bool { m := make([]bool, len(lines)) inBlock := false for i, line := range lines { trimmed := strings.TrimSpace(line) if strings.HasPrefix(trimmed, "```") { if inBlock { // closing fence — this line is still inside the block m[i] = true inBlock = false } else { // opening fence — this line is not inside content inBlock = true } continue } m[i] = inBlock } return m}
Findings inside code blocks are automatically downgraded one severity level (CRITICAL → HIGH, HIGH → MEDIUM, etc.).
Exclude Patterns
Rules can define exclude_patterns to suppress false positives:
internal/engine/pattern/matcher.go:148-173
func isExcluded(excludes []rules.CompiledPattern, lines []string, lineNum int) bool { if len(excludes) == 0 || lineNum < 1 || lineNum > len(lines) { return false } // Check the matched line and up to 3 lines before it start := max(lineNum-3, 1) for _, ep := range excludes { for i := start; i <= lineNum; i++ { line := lines[i-1] switch ep.Type { case rules.PatternRegex: if ep.Regex != nil && ep.Regex.MatchString(line) { return true } case rules.PatternContains: if strings.Contains(strings.ToLower(line), ep.Value) { return true } } } } return false}
If the matched line or the 3 lines before it match an exclude pattern, the finding is suppressed.
File: internal/engine/toxicflow/toxicflow.goThe Taint Tracker detects dangerous capability combinations within a single file — patterns that are safe in isolation but dangerous when combined.
var toxicPairs = []toxicPair{ { a: readsPrivateData, b: writesPublicOutput, ruleID: "TOXIC_001", name: "Private data read with public output", description: "Skill can read private data (credentials, SSH keys, env vars) AND write to public channels (Slack, Discord, email). This combination enables data exfiltration.", }, { a: readsPrivateData, b: executesCode, ruleID: "TOXIC_002", name: "Private data read with code execution", description: "Skill can read private data AND execute arbitrary code. This combination enables credential theft via dynamic code.", }, { a: destructive, b: executesCode, ruleID: "TOXIC_003", name: "Destructive actions with code execution", description: "Skill has destructive capabilities AND can execute arbitrary code. This combination enables ransomware-like attacks.", },}
File: internal/engine/rugpull/rugpull.goThe Rug-Pull Detector tracks file content changes across scans using SHA256 hashes. When a file’s content changes and the new version contains dangerous patterns, it emits a CRITICAL finding.