Sub topic 2
What Counts as a Secret or Sensitive Code
This chapter assumes you can use Git and a command line, have used an AI coding assistant, and know what an API key is. It defines which things you should keep away from AI tools. Later chapters cover the controls that keep them away.
You cannot protect what you have not named. A rule like "don't paste secrets" fails because people disagree about what a secret is. A database password is obvious. A customer's email address in a stack trace is less obvious. A pricing algorithm in a private repository is not a credential at all, yet it can matter more. This chapter gives you a working classification.
Three Categories of Sensitive Material
Sensitive material falls into three groups. Each group fails in a different way, so each needs a different control.
| Category | Examples | What goes wrong if it leaks |
|---|---|---|
| Credentials | API keys, passwords, tokens, private keys | Someone else can act as you or your service |
| Personal and regulated data | Customer records, health data, payment card numbers | Privacy harm, legal exposure, required breach notices |
| Proprietary code and business information | Unreleased features, algorithms, internal architecture, contracts | Competitors learn it, or you break a contract or licence |
Credentials are the most urgent category. A leaked credential can be used within minutes, and you can usually fix the damage by revoking it. Personal data and proprietary code are different. Once exposed, they cannot be taken back, so prevention matters more than cleanup.
Credentials
A credential is any value that proves identity or grants access. The common kinds are:
- API keys and access tokens. Long strings for cloud, payment, email, or SaaS services. Some have recognizable prefixes. AWS access key IDs start with
AKIA, and GitHub personal access tokens start withghp_orgithub_pat_. - Passwords. These include database passwords, admin passwords, and the password inside a connection string such as
postgres://app:[email protected]/orders. - Private keys. The secret half of a key pair, such as SSH keys, TLS certificate keys, and signing keys. These are usually in files ending in
.pemor.key. - Session cookies and bearer tokens. Values from an
Authorizationheader or a browser cookie. They expire, but while valid they work like a password. - Infrastructure state. Terraform state files (
terraform.tfstate) often contain resource passwords and keys in plain text, even when your code never mentions them. - Webhook signing secrets and OAuth client secrets. These let an attacker forge requests or impersonate your application.
Not every identifier is secret. An AWS access key ID alone is not enough to use the account, because the secret access key is the other half. A public OAuth client ID is designed to be visible. Treat the pair as sensitive anyway. The ID tells an attacker which account to target, and pasting both halves together is a common mistake.
Personal and Regulated Data
Developers often miss this category because it is not code. It arrives through logs, test fixtures, database dumps, and bug reports.
- Personally identifiable information (PII). Names, email addresses, phone numbers, home addresses, IP addresses, and government ID numbers.
- Financial data. Card numbers, bank account numbers, and transaction histories.
- Health data. Records covered by rules such as HIPAA in the United States.
- Data covered by contracts. Customer data you process under an agreement that limits where it can be sent.
Regulations such as GDPR can treat sending personal data to a third-party AI provider as a disclosure. Whether that is allowed depends on your agreements with the provider and your customers. You do not need to settle the legal question in every case. The practical rule is that real customer data does not go into a prompt unless your organization has approved that specific tool for that class of data.
Proprietary Code and Business Information
Source code is sensitive for more than its secrets. Consider these items:
- Algorithms and models that give your product an edge.
- Unreleased features and roadmaps.
- Internal architecture, hostnames, and network layouts, which help an attacker plan.
- Security findings, such as an unpatched vulnerability description.
- Third-party code you hold under a licence that restricts sharing.
- Contracts, pricing, and financial figures.
Open-source code you wrote and published is usually low risk. Private repositories, client work, and code under a non-disclosure agreement need a decision from someone with authority, not a guess.
Where Secrets Hide
Most leaks to AI tools are accidental. The developer did not paste a password on purpose. The secret was inside something else. These are the usual hiding places.
- Environment files.
.envfiles hold real values and sit in the project directory, where an assistant can read them. - Hardcoded values in source. A key typed into a script "just for testing."
- Configuration files. Files such as
config.yaml,settings.json, and Kubernetes manifests. - Shell history and dotfiles.
~/.bash_history,~/.aws/credentials,~/.npmrc, and~/.netrc. - Logs and error output. Stack traces, debug logs, and HTTP traces that include headers.
- Command output. Running
env,printenv, ordocker inspectprints every variable. - Git history. A secret deleted from the current file still exists in older commits.
- Test fixtures and database dumps. Copies of production data used for convenience.
The last two deserve emphasis. Git history means that removing a key from a file does not remove it from the repository. An assistant that can run git log -p or git show can read old versions. Fixtures mean that real data may sit in a folder called tests/, where nobody expects it.
Recognizing Secrets by Shape
Many secrets have a recognizable shape: a known prefix, a fixed length, or a labelled assignment. Secret scanners use these shapes, and so can you. This short script finds a few of them in a text file. It is a teaching example and not a complete detector.
import re
import sys
SHAPES = {
"AWS access key ID": re.compile(r"AKIA[0-9A-Z]{16}"),
"GitHub token": re.compile(r"gh[pousr]_[A-Za-z0-9]{36,}"),
"Private key block": re.compile(r"-----BEGIN [A-Z ]*PRIVATE KEY-----"),
"Labelled secret": re.compile(
r"(?i)(password|secret|token|api[_-]?key)\s*[=:]\s*\S+"
),
}
def scan(path: str) -> int:
hits = 0
with open(path, encoding="utf-8", errors="replace") as handle:
for number, line in enumerate(handle, start=1):
for label, pattern in SHAPES.items():
if pattern.search(line):
print(f"{path}:{number}: possible {label}")
hits += 1
return hits
if __name__ == "__main__":
total = sum(scan(name) for name in sys.argv[1:])
sys.exit(1 if total else 0)Run it as python shape_scan.py app.log config.yaml. It prints the file and line number but never prints the matched value, so the report itself does not leak the secret. It exits with status 1 when it finds something, which lets you use it in scripts.
The script has two weaknesses that apply to every shape-based detector. It misses secrets with no known pattern, such as a random 32-character internal token. It also flags harmless text, such as password = input("Password: "). Expect both false negatives and false positives.
A Quick Decision Guide
When you are unsure whether something can go into a prompt, follow this order.
Credentials are the strictest case. There is rarely a good reason to show a real credential to an assistant, because a placeholder such as YOUR_API_KEY gives the assistant the same information it needs to help you.
Common Mistakes
- Assuming a secret is safe because the repository is private. Private repositories get shared, forked, and breached. An assistant reading the working directory ignores repository visibility anyway.
- Treating "test" or "dev" keys as harmless. Development credentials often reach real systems, and attackers use them to move to others.
- Forgetting that deleting is not removing. A secret removed from the latest commit remains in history and must be treated as exposed.
- Trusting naming. A file called
example.jsonorbackup.txtcan hold real values. - Ignoring derived data. A summary or a sample row from a customer database is still customer data.
Building Your Own Inventory
A practical first step is a short inventory for each project. List the credentials the project uses and where each one lives. List the data classes that pass through it, such as customer emails or payment data. Mark which directories contain real data. This list drives everything that follows, including which paths to exclude from AI context and which patterns to scan for.
Exercise
You are debugging a failing payment call. Your terminal shows a log line POST /v1/charge Authorization: Bearer sk_live_9f3a... [email protected] status=401. Name the two categories of sensitive material in this line and say what you would put in an AI prompt instead.
Show answer
The bearer token is a credential, and the email address is personal data (PII). Replace them with placeholders, for example POST /v1/charge Authorization: Bearer [REDACTED] customer=[EMAIL] status=401. The 401 status and the endpoint are enough for an assistant to help. Because the live token was displayed in a log, you should also check whether it is stored in other logs and consider rotating it.
Exercise
A teammate removed an AWS secret access key from settings.py and committed the change. They say the problem is solved. Explain why it is not, and what must happen.
Show answer
The key still exists in earlier commits, and anyone or any tool that can read Git history can retrieve it. The key must be treated as exposed. It should be revoked or deactivated in AWS and replaced with a new key, and the code should read the new key from the environment. Rewriting history can be done as an extra step, but it does not replace revoking the key.