Security

Credentials in projects: what never belongs in the repository

An upload key in a configuration file, a password in a script: what is convenient quickly ends up in the version history and stays there. Separating secrets cleanly closes one of the most common gaps in software projects.

Airnite Editorial Team27 November 2026 · 3 min
Published
Reading time
3 min
Author
Airnite Editorial Team

In short

  • Passwords, keys and tokens belong in a vault or environment variables, never in the code.
  • A secret that has been committed once is considered compromised and is replaced immediately, not just deleted.
  • Public identifiers are not secrets but should still be classified deliberately.

What it is about

Almost every penetration test turns up the same finding: credentials in the source code. An API key in a configuration file, a database password in a script, an upload token in a helper tool. The MITRE CWE catalogue lists hard-coded credentials as a vulnerability class of its own.

The treacherous part: a secret that has once been stored in a Git repository stays in the history, even if it is deleted in the next version. If the repository is later shared, handed over to a service provider or accidentally made public, the key goes with it.

How it works

The principle is simple: code and secrets are kept separate. The code only knows where to find a secret, for example in an environment variable or a vault, not the secret itself. Files with local credentials such as .env are on the version control ignore list. The OWASP Secrets Management Cheat Sheet also recommends short lifetimes, minimal permissions and a central overview of which secrets exist and who uses them.

It is also important to distinguish between secret and public values. A web analytics measurement ID or a public key appears in the source of every page anyway and is not a secret. A token that can upload files to the server, on the other hand, is highly critical. Secret scanning tools, as offered by code platforms, find typical key patterns before or after the commit.

Where it goes wrong

The most common mistake is the test key that stays. A developer enters a key directly into a script to try something, intends to move it out later and forgets. A proven approach is an automated check before every commit that blocks such patterns, and the rule that helper tools read credentials only from the environment and stop with a clear message if the value is missing.

The second mistake is the wrong response to a leak. An accidentally committed key is deleted and the case is considered closed. In fact, it must be revoked and replaced immediately, because it is still in the history. And finally, credentials do not belong in handover notes, chats or tickets either. They only say where the key is kept.

How to proceed

Draw up a list of all credentials in your project with purpose, location and responsible person. Move secrets to a vault or environment variables and exclude local files such as .env from version control. Have every commit scanned automatically for keys and passwords. Issue tokens with minimal permissions and an expiry date. Classify public identifiers deliberately as public. And revoke accidentally published secrets immediately instead of just deleting them.

Read more: Secure software development: what the NIST SSDF requires, Version control for websites: every state traceable and Static websites: less technology, less attack surface.

How Airnite helps

In a penetration test, we search your repositories and configurations for credentials, including the entire version history, and help revoke and replace them. For new projects, we set up the separation of code and secrets and automated checks, and train your development team in handling keys securely.

Checklist

Sources

Every fact in this article is based on the following publications. Primary sources are marked.

  1. OWASPSecrets Management Cheat SheetStandardPrimary source
  2. MITRECWE-798: Use of Hard-coded CredentialsStandardPrimary source
  3. GitHub DocsAbout secret scanningVendor

Matching services

Read on

Current incidents and warnings are covered in the Zero Day magazine. Go to the magazine

Want to put this into practice in your company?

We assess your situation and tell you clearly what to do. For businesses, in confidence.

Talk to an expert now