Set Up Secret Scanning with AI Prompts

Share

TL;DR

These prompts help you set up automated secret scanning at multiple levels: pre-commit hooks to catch secrets before they're committed, GitHub Actions for CI/CD checks, and repository settings for continuous monitoring. This layered approach catches credentials before they become a problem.

Pre-Commit Hook Setup

The best defense is preventing secrets from ever being committed. Use this prompt to set up pre-commit hooks:

Pre-Commit Hooks Setup

Set up pre-commit hooks to scan for secrets before any commit.

I want to use a tool like:

  • detect-secrets (Python, very thorough)
  • gitleaks (Go, fast)
  • truffleHog (Python, checks git history too)

Please:

  1. Create the pre-commit configuration file
  2. Add common secret patterns to detect
  3. Set up allowlisting for false positives
  4. Add installation instructions for team members
  5. Make it work on both Mac and Linux

The hook should:

  • Block commits containing potential secrets
  • Show clear error messages about what was detected
  • Provide a way to allowlist false positives
  • Be fast enough to not slow down development

Also create documentation for the team on how to use it.

GitHub Actions Secret Scanning

GitHub Actions Scanner

Create a GitHub Actions workflow that scans for secrets on every PR and push.

Requirements:

  1. Run on all pull requests and pushes to main
  2. Use gitleaks or similar tool
  3. Scan only changed files for PRs (faster)
  4. Scan entire repo on main branch pushes
  5. Fail the CI if secrets are detected
  6. Output results in a clear format

The workflow should:

  • Not block legitimate commits (handle false positives)
  • Run quickly (under 2 minutes for typical repos)
  • Support a configuration file for custom rules
  • Send notifications on failures

Create:

  1. .github/workflows/secret-scan.yml
  2. .gitleaks.toml with project-specific configuration
  3. Documentation on how to handle detected secrets

GitHub Built-in Secret Scanning

Enable GitHub Secret Scanning

Help me enable and configure GitHub's built-in secret scanning.

I need to know:

  1. How to enable secret scanning in repository settings
  2. What types of secrets GitHub detects automatically
  3. How to view and manage alerts
  4. How to configure push protection (block commits with secrets)
  5. How GitHub notifies service providers when their tokens are found

Also explain:

  • Is this free for my repository type (public/private)?
  • What's the difference between secret scanning and push protection?
  • How do I handle false positives?
  • Can I add custom secret patterns?

Give me step-by-step instructions to enable all available protections.

Custom Pattern Detection

Custom Secret Patterns

Create custom secret detection patterns for my project.

I need to detect:

  1. Internal API keys with our company's format
  2. Database connection strings for our specific services
  3. Custom authentication tokens
  4. Service-specific credentials

For each pattern:

  1. Create a regex that matches it
  2. Minimize false positives
  3. Add to both pre-commit and CI configurations
  4. Document what each pattern detects

Also create patterns to avoid false positives:

  • Test/example values
  • Documentation references
  • Placeholder strings

Format the output for both gitleaks.toml and pre-commit config.

Layer your defenses: Use both pre-commit hooks (prevents commits) and CI scanning (catches anything that slips through). Pre-commit hooks can be skipped with --no-verify, so CI is your safety net.

Scan Existing Repository

Full Repo Scan

Help me scan my existing repository for secrets that may have been committed in the past.

I need to:

  1. Scan all current files for secrets
  2. Scan the entire git history for past secrets
  3. Generate a report of findings
  4. Prioritize by severity (live keys vs test keys)

For any secrets found:

  1. Identify when they were committed
  2. Check if they're still present in current code
  3. Determine if they're in the git history only
  4. Recommend remediation steps

After the scan:

  • List all secrets that need rotation
  • Show which files in history need cleaning
  • Provide commands to clean git history if needed

Pro tip: After setting up scanning, do a full audit of your repository history. Many secrets are committed early in a project and forgotten. Use tools like truffleHog or gitleaks with history scanning enabled.

What is secret scanning?

Secret scanning automatically detects credentials, API keys, and other secrets in your code. It can run as a pre-commit hook, in CI/CD, or as a service that monitors your repository.

Is GitHub secret scanning free?

Yes for public repositories. For private repositories, GitHub secret scanning is available with GitHub Advanced Security, which requires a paid plan.

What's the difference between pre-commit hooks and CI scanning?

Pre-commit hooks run locally before you commit, preventing secrets from ever entering git history. CI scanning runs after commits and catches anything that slipped through. Both are recommended.

Scan Your Repository Now

Don't wait to set up scanning. Check your repo for exposed secrets immediately.

Start Free Scan
AI Fix Prompts

Set Up Secret Scanning with AI Prompts