Skip to content

fix: improve detector quality, config resolution, code quality, and binary detection#57

Merged
pixincreate merged 4 commits into
masterfrom
fix/config-detector-quality-v2
May 11, 2026
Merged

fix: improve detector quality, config resolution, code quality, and binary detection#57
pixincreate merged 4 commits into
masterfrom
fix/config-detector-quality-v2

Conversation

@pixincreate
Copy link
Copy Markdown
Owner

Summary

Address code review findings from PR #56 with the following fixes:

High Priority

  1. Config path resolution (src/detector.rs)

    • Multi-tier fallback: env var → ~/.config/keywatch/ → exe dir → CWD
    • Fixes config not found when installed via cargo install
  2. Detector quality (detectors.toml)

    • Remove duplicate Google/Firebase/YouTube API key detectors (same pattern)
    • Fix IPAddressDetector to only match valid first octet (1-223)
    • Raise HighEntropyDetector threshold from 32+ to 48+ to avoid SHA1/UUIDs
    • Remove LinkedInSecretDetector (too broad, no specific pattern)

Medium Priority

  1. Scanner deduplication (src/scanner.rs)

    • Use HashMap instead of manual Vec loop for deduplication
  2. Report improvements (src/report.rs, src/lib.rs)

    • Single-pass severity counting instead of triple iteration
    • Add Severity and ScanStatus enums with serde(uppercase)
    • Remove hardcoded "HIGH", "MEDIUM", "LOW", "PASS", "FAIL" strings
  3. Binary file detection (src/scanner.rs)

    • Add is_binary() function to skip binary files
    • Check first 8KB for null bytes to detect binary content

Testing

  • All tests pass
  • cargo fmt / clippy clean

Notes

  • Combined into one PR for simplicity as requested

@pixincreate pixincreate requested a review from Copilot May 10, 2026 18:50
@pixincreate pixincreate self-assigned this May 10, 2026
@pixincreate pixincreate added the enhancement New feature or request label May 10, 2026
@pixincreate pixincreate force-pushed the fix/config-detector-quality-v2 branch from 3506efb to abd7872 Compare May 10, 2026 18:52
- Priority 1: KEYWATCH_CONFIG_PATH env var (override)
- Priority 2: ~/.config/keywatch/detectors.toml
- Priority 3: executable directory (development)
- Priority 4: CWD (last resort)

Fixes config not found when installed via cargo install.
- Remove duplicate Google/Firebase/YouTube API key detectors (same pattern)
- Fix IPAddressDetector to only match valid first octet (1-223)
- Raise HighEntropyDetector threshold from 32+ to 48+ to avoid SHA1
- Remove LinkedInSecretDetector (too broad, no specific pattern)
- Add CWD fallback in config resolution for test compatibility

Fixes false positives and removes redundant detectors.
- scanner.rs: use HashMap for deduplication instead of manual Vec loop
- report.rs: add Severity and ScanStatus enums with serde(uppercase)
- report.rs: single-pass severity counting instead of triple iteration
- lib.rs: update to use Severity enum in tests and exit code logic

Reduces code complexity and removes hardcoded string values
@pixincreate pixincreate force-pushed the fix/config-detector-quality-v2 branch from 2fc9639 to 220f1d2 Compare May 10, 2026 19:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 9 comments.

Comment thread src/report.rs
Comment thread src/lib.rs
Comment thread src/detector.rs Outdated
Comment thread src/scanner.rs
Comment thread src/scanner.rs Outdated
Comment thread src/scanner.rs Outdated
Comment thread detectors.toml
Comment thread src/report.rs
Comment thread src/report.rs
@pixincreate pixincreate force-pushed the fix/config-detector-quality-v2 branch from 220f1d2 to cba40a0 Compare May 11, 2026 07:13
- scanner.rs: add is_binary() function to check for null bytes
- skip first 8KB of file to detect binary content
- binary files are skipped during scanning to avoid false positives
- update tests to use Severity enum
@pixincreate pixincreate force-pushed the fix/config-detector-quality-v2 branch from cba40a0 to 84e2e1e Compare May 11, 2026 07:16
@pixincreate pixincreate merged commit e42a0ce into master May 11, 2026
5 checks passed
@pixincreate pixincreate deleted the fix/config-detector-quality-v2 branch May 11, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants