Skip to main content

Secret Scanning

Rafter scans your code for secrets and credentials to prevent accidental leaks.

Quick Start

Scan a directory for secrets:
Note: rafter agent scan still works but is deprecated — it will be removed in a future major version.

Detected Secret Types

Rafter detects 21+ types of secrets:
  • AWS Access Keys & Secret Keys
  • Google API Keys & OAuth credentials
  • Azure credentials
  • GitHub Personal Access Tokens
  • GitHub OAuth Tokens
  • GitHub App Tokens
  • GitHub Refresh Tokens
  • Stripe API Keys (live & restricted)
  • Slack Tokens & Webhooks
  • Twilio API Keys
  • npm Access Tokens
  • PyPI API Tokens
  • Database connection strings (postgres, mysql, mongodb)
  • Private keys (RSA, DSA, EC, OpenSSH)
  • JWT tokens
  • Generic API keys

Usage Examples

Scan Specific File

Scan Directory

Quiet Mode (CI/CD)

Only output if secrets are found:
Exits with code 1 if secrets found, perfect for CI pipelines.

JSON Output

Get machine-readable results:

Watch Mode

Watch a path for file changes and re-scan automatically:
Findings are printed inline and logged to audit.jsonl in real time. Press Ctrl+C to stop. Watch mode does not exit on findings — it keeps watching.
Requires chokidar (Node, bundled) or watchdog (Python: pip install watchdog).

Diff Scanning

Scan only files changed since a git ref:
Useful for CI pipelines that only need to check new or modified files.

Output Format

When secrets are found, Rafter shows:

Severity Levels

Severity Indicators

  • 🔴 Critical: Immediate security risk (AWS keys, database passwords)
  • 🟠 High: Significant risk (generic API keys, bearer tokens)
  • 🟡 Medium: Moderate risk (connection strings without credentials)
  • 🟢 Low: Low risk (public keys, non-sensitive patterns)

Smart Redaction

Rafter uses smart redaction to show context without exposing secrets:
  • Short secrets (≤8 chars): Fully redacted (********)
  • Long secrets (>8 chars): Show first 4 and last 4 characters
Example: AKIAIOSFODNN7EXAMPLEAKIA************MPLE

Pre-Commit Scanning

Integrate with git commits:

Excluding Files

Rafter automatically skips:
  • Binary files (images, PDFs, executables)
  • Build directories (node_modules, dist, build, .next)
  • Version control (.git)
  • IDE folders (.vscode, .idea)

CI/CD Integration

GitHub Actions

Exit code 1 will fail the pipeline if secrets are detected.

GitLab CI

Audit Trail

All scans are logged to ~/.rafter/audit.jsonl:

False Positives

If you encounter false positives:
  1. Exclude patterns via config:
  2. Report issues: Help improve detection at rafter-cli/issues

Advanced Usage

Scan with Custom Patterns

Define custom patterns in .rafter.yml:
See Policy File for full configuration options.

Engine Selection

Rafter ships two scan engines, selectable via --engine:
Install Betterleaks (the gitleaks successor maintained by the same authors) via rafter agent init --with-betterleaks for enhanced detection.

Respecting .gitignore

When the scan target sits inside a git work tree, Rafter honors .gitignore by default — files the repo has excluded (build outputs, vendored deps, scratch envs) are not scanned. Every gitignore semantic git itself supports is honored: nested .gitignore files, negations, .git/info/exclude, and the configured global excludes file.
Scans against directories outside a git work tree (a plain unversioned folder) fall back to scanning every candidate file, since there’s no work tree for the filter to consult. The betterleaks engine has always honored .gitignore (gitleaks ancestry); the built-in patterns engine reached parity in the same release that introduced --no-gitignore.

Best Practices

Recommended Workflow

  1. Run rafter secrets before every commit
  2. Configure pre-commit hooks for automation
  3. Use --quiet mode in CI/CD pipelines
  4. Review audit logs regularly
  5. Report false positives to improve accuracy

Next Steps

Command Execution

Learn about safe command execution

Command Reference

Complete CLI command reference