API Key and Token Leaks

API keys and tokens are forms of authentication commonly used to manage permissions and access to both public and private services. Leaking these sensitive pieces of data can lead to unauthorized access, compromised security, and potential data breaches.

Summary

Tools

Methodology

  • API Keys: Unique identifiers used to authenticate requests associated with your project or application.

  • Tokens: Security tokens (like OAuth tokens) that grant access to protected resources.

Common Causes of Leaks

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

  • Public Repositories: Accidentally committing sensitive keys and tokens to publicly accessible version control systems like GitHub.

  • Hardcoding in Docker Images: API keys and credentials might be hardcoded in Docker images hosted on DockerHub or private registries.

  • 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.).

Validate The API Key

If assistance is needed in identifying the service that generated the token, mazen160/secrets-patterns-dbarrow-up-right can be consulted. It is the largest open-source database for detecting secrets, API keys, passwords, tokens, and more. This database contains regex patterns for various secrets.

Use streaak/keyhacksarrow-up-right or read the documentation of the service to find a quick way to verify the validity of an API key.

  • Example: Telegram Bot API Token

Reducing The Attack Surface

Check the existence of a private key or AWS credentials before commiting your changes in a GitHub repository.

Add these lines to your .pre-commit-config.yaml file.

References

Last updated