Skip to content

feat: user config file, SARIF output, detector overrides, pre-commit hooks - #73

Merged
pixincreate merged 26 commits into
masterfrom
feat/config-sarif-more
Aug 2, 2026
Merged

feat: user config file, SARIF output, detector overrides, pre-commit hooks#73
pixincreate merged 26 commits into
masterfrom
feat/config-sarif-more

Conversation

@pixincreate

Copy link
Copy Markdown
Owner

Summary

Implements the remaining non-CI/CD feature gaps from #71: user-configurable .keywatch.toml, SARIF output format, per-detector enable/disable and severity overrides, and pre-commit framework support.

Changes

User Config (.keywatch.toml)

  • New src/config.rs module for loading and parsing user config
  • Config file discovered at --config <path> or auto-detected (.keywatch.tomlkeywatch.toml.kw.toml)
  • Custom rules: add detectors beyond the built-in detectors.toml
  • Detector overrides: disable any built-in detector, or override its severity
  • Exclude patterns: additional exclude patterns merged with --exclude CLI flag

Example config:

[[rules]]
name = "MyCustomDetector"
pattern = "\\bSECRET_[A-Z]+\\b"
finding_type = "Custom Secret"
severity = "HIGH"

[overrides]
AWSKeyDetector = { enabled = false }
GitHubTokenDetector = { severity = "CRITICAL" }

exclude = ["*.test.js"]

SARIF Output

  • New --format flag: key-watch scan <paths> --format sarif
  • Generates SARIF 2.1.0 compliant JSON output
  • Severity mapping: CRITICAL/HIGH → error, MEDIUM → warning, LOW → note
  • Includes tool metadata, file locations with line numbers, and severity in SARIF properties

CRITICAL Severity

  • New Severity::Critical variant (serialized as CRITICAL)
  • from_string() now recognizes "CRITICAL"
  • Merged into get_severity_counts (Critical counted with High)
  • Exit code calculations updated to treat Critical as High

Per-Detector Enable/Disable

  • Config overrides can disable detectors by name (enabled = false)
  • Disabled detectors are filtered out before scanning
  • Severity overrides change severity at scan time

Pre-Commit Framework

CRITICAL Severity Variant

This PR reinstates the CRITICAL severity level (also in PR #69, not yet in master) so users can flag high-value secrets (AWS root, GitHub PATs) above standard HIGH.

Future Work (not in this PR)

  • Expression-based allowlists (CEL)
  • Secrets validation (async HTTP credential check)
  • Homebrew formula

@pixincreate
pixincreate force-pushed the feat/config-sarif-more branch 3 times, most recently from ebb9d17 to 83613f4 Compare July 30, 2026 16:38
@pixincreate
pixincreate changed the base branch from master to feat/github-action-docker July 30, 2026 16:38
@pixincreate
pixincreate requested a review from Copilot August 1, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR closes the remaining feature gaps from #71 by adding user-configurable scanning behavior via a TOML config file, introducing SARIF output for Code Scanning integration, and expanding integration support via pre-commit hooks, while also reinstating CRITICAL severity handling across the reporting/exit-code pipeline.

Changes:

  • Added .keywatch.toml support (custom rules, per-detector enable/disable + severity overrides, and config-driven exclude patterns).
  • Added --format with SARIF 2.1.0 output generation alongside JSON.
  • Refactored hook install/uninstall into src/hooks.rs and added pre-commit framework hook definitions.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/scanner_tests.rs Updates tests for new ScanArgs fields and run_scan signature.
src/scanner.rs Accepts optional config, applies detector overrides, and merges config exclude patterns.
src/report.rs Adds CRITICAL severity and implements SARIF report generation.
src/lib.rs Loads config, selects JSON vs SARIF output, and routes hook commands through hooks module.
src/hooks.rs Implements install_hook/uninstall_hook and hook-safety logic in the hooks module.
src/config.rs Introduces config parsing/loading and applying custom rules/overrides/excludes to detectors.
src/cli.rs Adds --config and --format CLI options plus OutputFormat enum.
README.md Adds an architecture section and references the new diagram.
docs/architecture.svg Adds an SVG architecture diagram for documentation.
CHANGELOG.md Documents config, SARIF, CLI flag changes, and updated severity counts/run_scan signature.
.pre-commit-hooks.yaml Adds pre-commit hook metadata for KeyWatch scanning.
Suppressed comments (2)

src/report.rs:120

  • SARIF result objects require ruleId, but this struct currently serializes rule_id (snake_case), which breaks SARIF 2.1.0 schema expectations.
    #[derive(Serialize)]
    struct SarifResult {
        rule_id: String,
        level: &'static str,
        message: SarifMessage,

src/report.rs:134

  • SARIF location fields are currently serialized as physical_location, artifact_location, and start_line (snake_case). SARIF 2.1.0 expects physicalLocation, artifactLocation, and startLine, so the report will not be schema-compliant.
    #[derive(Serialize)]
    struct SarifLocation {
        physical_location: SarifPhysicalLocation,
    }

Comment thread src/report.rs Outdated
Comment thread src/report.rs Outdated
Comment thread src/report.rs Outdated
Comment thread src/config.rs Outdated
Comment thread src/config.rs Outdated
Comment thread src/lib.rs
@pixincreate
pixincreate force-pushed the feat/github-action-docker branch from 7e20919 to e543e6d Compare August 1, 2026 18:28
@pixincreate
pixincreate force-pushed the feat/config-sarif-more branch from 6cbb2bc to 90caf45 Compare August 1, 2026 18:29
@pixincreate
pixincreate force-pushed the feat/github-action-docker branch from e543e6d to 699f621 Compare August 1, 2026 18:52
@pixincreate
pixincreate force-pushed the feat/config-sarif-more branch 2 times, most recently from a009937 to e8b339f Compare August 2, 2026 08:20
Base automatically changed from feat/github-action-docker to master August 2, 2026 08:23
@pixincreate
pixincreate changed the base branch from master to feat/github-action-docker August 2, 2026 08:32
Base automatically changed from feat/github-action-docker to master August 2, 2026 08:35
@pixincreate pixincreate self-assigned this Aug 2, 2026
@pixincreate pixincreate added the enhancement New feature or request label Aug 2, 2026
@pixincreate
pixincreate changed the base branch from master to feat/github-action-docker August 2, 2026 08:38
@pixincreate
pixincreate force-pushed the feat/config-sarif-more branch from e8b339f to 3561e18 Compare August 2, 2026 09:14
@pixincreate
pixincreate deleted the branch master August 2, 2026 09:21
@pixincreate pixincreate closed this Aug 2, 2026
@pixincreate pixincreate reopened this Aug 2, 2026
@pixincreate
pixincreate changed the base branch from feat/github-action-docker to master August 2, 2026 09:21
@pixincreate pixincreate closed this Aug 2, 2026
@pixincreate pixincreate reopened this Aug 2, 2026
@pixincreate
pixincreate merged commit 7b66a62 into master Aug 2, 2026
5 checks passed
@pixincreate
pixincreate deleted the feat/config-sarif-more branch August 2, 2026 10:25
@pixincreate pixincreate added the clanker changes done by ai under author's supervision. label Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clanker changes done by ai under author's supervision. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants