Secure Coding & Release Discipline ยท Lesson 2 of 4
Secrets out of source code
Study notesAbout 3 minutes. A full lesson with quick checks is on its way.
In short
Keep passwords, API keys and tokens out of source code. Store them in a secrets manager or environment settings the application reads when it runs.
In your work
Refactoring a client's old website, you find their payment provider's live key hard-coded in a config file, so it's in every clone and backup. You move it into the hosting platform's secret storage, rotate it and add a secret scanner.
What the UK rules say
- The NCSC's secure development principles say to separate secret credentials from source code.
- If a leaked key can reach personal data, your organisation may need to treat it as a personal data breach under UK GDPR.
What to do
- Load secrets from a secrets manager or environment variables, never constants.
- Run a secret scanner before commits and in the pipeline.
- Use separate keys for test and live, each with the least access it needs.
- Rotate any secret that has ever been committed.
Watch out for
- Committing .env files or config with real keys 'for now'.
- Pasting keys into tickets, chat or AI tools.
In your organisation
Which secrets manager does your organisation use, and who can grant access to it?
Your employer's own policies come first.
Sources
- NCSC, Secure development principles: protect your code repository (opens in a new tab), checked 6 October 2026.
- OWASP, Secrets Management Cheat Sheet (opens in a new tab), checked 6 October 2026.
- ICO, Personal data breaches: a guide (opens in a new tab), checked 6 October 2026.
UK law and guidance, explained for learning. Not legal advice.
