TruffleHog – Search Through git Repositories For Secrets, Digging Deep Into Commit History & Branches


Searches through git repositories for secrets, digging deep into commit history and branches. This is effective at finding secrets accidentally committed.


GitHub scanning demo
docker run -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity


Example 1: Scan a repo for only verified secrets


trufflehog git --only-verified

Expected output:

πŸ·πŸ”‘πŸ·  TruffleHog. Unearth your secrets. πŸ·πŸ”‘πŸ·

Found verified result πŸ·πŸ”‘
Detector Type: AWS
Decoder Type: PLAIN
Line: 4
Commit: fbc14303ffbf8fb1c2c1914e8dda7d0121633aca
File: keys
Email: counter <counter@counters-MacBook-Air.local>
Timestamp: 2022-06-16 10:17:40 -0700 PDT

Example 2: Scan a GitHub Org for only verified secrets

trufflehog github --org=trufflesecurity --only-verified

Example 3: Scan a GitHub Repo for only verified keys and get JSON output


trufflehog git --only-verified --json

Expected output:

{"SourceMetadata":{"Data":{"Git":{"commit":"fbc14303ffbf8fb1c2c1914e8dda7d0121633aca","file":"keys","email":"counter \u003ccounter@counters-MacBook-Air.local\u003e","repository":"","timestamp":"2022-06-16 10:17:40 -0700 PDT","line":4}}},"SourceID":0,"SourceType":16,"SourceName":"trufflehog - git","DetectorType":2,"DetectorName":"AWS","DecoderName":"PLAIN","Verified":true,"Raw":"AKIAYVP4CIPPERUVIFXG","Redacted":"AKIAYVP4CIPPERUVIFXG","ExtraData":{"account":"595918472158","arn":"arn:aws:iam::595918472158:user/","user_id":"AIDAYVP4CIPPJ5M54LRCY"},"StructuredData":null}

Example 4: Scan an S3 bucket for verified keys

trufflehog s3 --bucket=<bucket name> --only-verified


  • All I see is πŸ·πŸ”‘πŸ· TruffleHog. Unearth your secrets. πŸ·πŸ”‘πŸ· and the program exits, what gives?
    • That means no secrets were detected
  • Why is the scan is taking a long time when I scan a GitHub org
    • Unauthenticated GitHub scans have rate limits. To improve your rate limits, include the --token flag with a personal access token
  • It says a private key was verified, what does that mean?
    • Check out our Driftwood blog post to learn how to do this, in short we’ve confirmed the key can be used live for SSH or SSL Blog post

What’s new in v3?

TruffleHog v3 is a complete rewrite in Go with many new powerful features.

  • We’ve added over 700 credential detectors that support active verification against their respective APIs.
  • We’ve also added native support for scanning GitHub, GitLab, filesystems, and S3.
  • Instantly verify private keys against millions of github users and billions of TLS certificates using our Driftwood technology.

What is credential verification?

For every potential credential that is detected, we’ve painstakingly implemented programatic verification against the API that we think it belongs to. Verification eliminates false positives. For example, the AWS credential detector performs a GetCallerIdentity API call against the AWS API to verify if an AWS credential is active.


Several options:

1. Go

git clone

cd trufflehog; go install

2. Release binaries

3. Docker

Note: Apple M1 hardware users should run with docker run --platform linux/arm64 for better performance.

Most users

docker run -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo

Apple M1 users

The linux/arm64 image is better to run on the M1 than the amd64 image. Even better is running the native darwin binary available, but there is no container image for that.

docker run --platform linux/arm64 -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo 

4. Pip (help wanted)

It’s possible to distribute binaries in pip wheels.

Here is an example of a project that does it.

Help with setting up this packaging would be appreciated!

5. Brew

brew install trufflesecurity/trufflehog/trufflehog


TruffleHog has a sub-command for each source of data that you may want to scan:

  • git
  • github
  • gitlab
  • S3
  • filesystem
  • syslog
  • file and stdin (coming soon)

Each subcommand can have options that you can see with the --help flag provided to the sub command:

$ trufflehog git --help
usage: TruffleHog git [<flags>] <uri>

Find credentials in git repositories.

      --help                     Show context-sensitive help (also try --help-long and --help-man).
      --debug                    Run in debug mode
      --version                  Prints trufflehog version.
  -j, --json                     Output in JSON format.
      --json-legacy              Use the pre-v3.0 JSON format. Only works with git, gitlab, and github sources.
      --concurrency=1            Number of concurrent workers.
      --no-verification          Don't verify the results.
      --only-verified            Only output verified results.
      --filter-unverified        Only output first unverified result per chunk per detector if there are more than one results.
      --print-avg-detector-time  Print the average time spent on each detector.
      --no-update                Don't check for updates.
  -i, --include-paths=INCLUDE-PATHS
                                 Path to file with newline separated regexes for files to include in scan.
  -x, --exclude-paths=EXCLUDE-PATHS
                                 Path to file with newline separated regexes for files to exclude in scan.
                                 Commit to start scan from.
      --branch=BRANCH            Branch to scan.
      --max-depth=MAX-DEPTH      Maximum depth of commits to scan.
      --allow                    No-op flag for backwards compat.
      --entropy                  No-op flag for backwards compat.
      --regex                    No-op flag for backwards compat.

  <uri>  Git repository URL. https://, file://, or ssh:// schema expected.

For example, to scan a git repository, start with

$ trufflehog git

Exit Codes:

  • 0: No errors and no results were found.
  • 1: An error was encountered. Sources may not have completed scans.
  • 183: No errors were encountered, but results were found. Will only be returned if --fail flag is used.

Scanning an organization

Try scanning an entire GitHub organization with the following:

docker run -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity

TruffleHog OSS Github Action

- name: TruffleHog OSS
  uses: trufflesecurity/trufflehog@main
    # Repository path
    # Start scanning from here (usually main branch).
    # Scan commits until here (usually dev branch).
    head: # optional
    # Extra args to be passed to the trufflehog cli.
    extra_args: --debug --only-verified

The TruffleHog OSS Github Action can be used to scan a range of commits for leaked credentials. The action will fail if any results are found.

For example, to scan the contents of pull requests you could use the following workflow:

name: Leaked Secrets Scan
on: [pull_request]
    runs-on: ubuntu-latest
      - name: Checkout code
        uses: actions/checkout@v3
          fetch-depth: 0
      - name: TruffleHog OSS
        uses: trufflesecurity/trufflehog@main
          path: ./
          base: ${{ github.event.repository.default_branch }}
          head: HEAD
          extra_args: --debug --only-verified

Precommit Hook

Trufflehog can be used in a precommit hook to prevent credentials from leaking before they ever leave your computer. An example .pre-commit-config.yaml is provided (see for installation).

- repo: local
    - id: trufflehog
      name: TruffleHog
      description: Detect secrets in your data.
      entry: bash -c 'trufflehog git file://. --since-commit HEAD --only-verified --fail'
      # For running trufflehog in docker, use the following entry instead:
      # entry: bash -c 'docker run -v "$(pwd):/workdir" -i --rm trufflesecurity/trufflehog:latest git file:///workdir --since-commit HEAD --only-verified --fail'
      language: system
      stages: ["commit", "push"]

Use as a library

Currently, trufflehog is in heavy development and no guarantees can be made on the stability of the public APIs at this time.


Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *