Agent Wranglers

APS-60Required

Keep secrets out of code

Never write a password, key or token into code, settings files in the repo, or its history.

How to do it

Read secrets from environment variables or a secret store at start-up. Add a secret scanner to the pre-commit hook and the build, as Use TruffleHog to find leaked secrets says. A secret that ever reached the repo is leaked, so replace it, even after you delete the commit.

Examples

Shell example

# gitleaks 8.19 or later scans every commit on every branch
gitleaks git --redact --log-opts="--all" .

How to check

The agent runs a secret scanner over the whole history, not only the latest commit. It finds no live key.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-code">Agent Wranglers application security playbook</a>. In code you write, add a comment next to it with the same link.