Sub topic 2
What Counts as a Secret or Sensitive Code
This chapter assumes you can use Git and a command line, know what an API key is for, and have used an AI coding assistant. It defines what you need to protect, so later chapters can show how to protect it.
Two categories to protect
Not everything sensitive looks like a password. It helps to split the material into two groups.
- Secrets are values that grant access. Anyone who holds the value can act as you or your system.
- Sensitive code and data are things that do not grant access but would cause harm if exposed, such as proprietary logic or customer records.
A secret can be revoked and replaced. Sensitive code and personal data often cannot be taken back once shared. That difference shapes how you respond to a leak.
Common kinds of secrets
| Kind | Examples | Typical location |
|---|---|---|
| API keys and tokens | Cloud access keys, payment API keys, personal access tokens | `.env` files, shell history, CI settings |
| Passwords and connection strings | Database URLs with embedded credentials | Config files, ORM settings |
| Private keys and certificates | `*.pem`, `*.key`, SSH keys, signing keys | Home directory, repository root |
| Session material | Cookies, bearer tokens, JWTs | Logs, HTTP traces, browser exports |
| Infrastructure state | `terraform.tfstate` | Local working directory |
Infrastructure state is easy to miss. Terraform state files can hold resource attributes, including passwords, in plain text, even when your .tf files contain none.
Sensitive code and data
Treat these as sensitive even though they contain no credentials:
- Proprietary algorithms, pricing logic, and unreleased features.
- Customer data and personal information in fixtures, dumps, or logs.
- Internal hostnames, network layouts, and architecture notes.
- Unpatched vulnerability details.
- Code under a license or contract that restricts disclosure.
Your organization may already label data with classes such as public, internal, and confidential. If it does, use those labels to decide what may be sent to which tool.
Where secrets hide
Most leaks to AI tools are accidental. The assistant reads a file you did not think about, or you paste output that contains a value you did not notice.
Check these places first:
- Hardcoded values in source files.
- Untracked local files such as
.env, which exist on disk and are readable by an assistant even though Git ignores them. - Command output, such as
env,printenv, or verbose HTTP logs. - Old Git history, where a deleted secret is still readable.
- Test fixtures and sample data copied from production.
A quick self-audit
You can search a repository for likely credential shapes before you work with an assistant. This is a rough check and will miss unusual formats.
grep -rnE "AKIA[0-9A-Z]{16}|(password|secret|token|api[_-]?key)\s*[=:]" . \
--exclude-dir=.git --exclude-dir=node_modulesExpect false positives, such as variable names with no real value. Review each hit by hand.
Common mistakes
- Assuming only passwords count, and ignoring tokens, cookies, and state files.
- Treating a secret in a private repository as safe. Private repositories can be cloned, forked, or opened to more people later.
- Assuming a deleted line is gone. The value remains in Git history.
- Forgetting that non-credential data, such as customer records, also needs protection.
Exercise
A teammate says a file is safe to share with an assistant because it is listed in .gitignore. A second file, terraform.tfstate, has no passwords in the .tf source. Name two reasons both claims are unreliable.
Show answer
First, .gitignore only controls what Git tracks. The assistant can still read the file from disk, so it can enter the AI context. Second, terraform.tfstate can store resource attributes such as database passwords in plain text, so a clean .tf file does not mean the state file is clean. Both files need separate exclusion from AI context.