API Key Leaks: Common Causes of Leaks

Leaked secrets and API keysExploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

  • Hardcoding in Source Code: Developers may unintentionally leave API keys or tokens directly in the source code.

    py
    # Example of hardcoded API key
    api_key = "1234567890abcdef"
  • Public Repositories: Accidentally committing sensitive keys and tokens to publicly accessible version control systems like GitHub.

    ps1
    ## Scan a Github Organization
    docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity
    
    ## Scan a GitHub Repository, its Issues and Pull Requests
    docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys --issue-comments --pr-comments
  • Hardcoding in Docker Images: API keys and credentials might be hardcoded in Docker images hosted on DockerHub or private registries.

    ps1
    # Scan a Docker image for verified secrets
    docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest docker --image trufflesecurity/secrets
  • Logs and Debug Information: Keys and tokens might be inadvertently logged or printed during debugging processes.

  • Configuration Files: Including keys and tokens in publicly accessible configuration files (e.g., .env files, config.json, settings.py, or .aws/credentials.).

Comments

No comments yet.