# .env files with secrets in the repository
*Secrets*
Do not commit .env files that contain real secrets. Commit an example file with empty values instead.

## Why it matters
A committed .env is the fastest way to hand over database passwords and API keys. The history keeps it even after deletion.
An example file gives new developers the list of variables without exposing the values.

## How to fix it
1. Add .env to .gitignore
2. Commit .env.example with empty values
3. Remove the file from history if it was committed
4. Rotate every secret it contained

## Prompt for an AI assistant
Copy the text below and paste it into an AI assistant.
```text
You are the person improving this website. Check the item below and fix it if it applies to the site.

Item: .env files with secrets in the repository
Summary: Do not commit .env files that contain real secrets. Commit an example file with empty values instead.
Steps:
1. Add .env to .gitignore
2. Commit .env.example with empty values
3. Remove the file from history if it was committed
4. Rotate every secret it contained
References:
- Secrets Management (OWASP) (https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)

Constraints:
- Keep the existing design and tone of voice.
- Show the file or section you changed and the suggested final wording.
- Do not decide ambiguous points alone; give options and a recommendation.
- Do not change anything outside the listed item.
```

## Related checks
- **[API keys written in the source](https://ismyappok.com/en/checks/hardcoded-secrets)** — Keep API keys and tokens out of source files, and load them from environment variables instead.
- **[.env file exposure](https://ismyappok.com/en/checks/env-file-exposure)** — Make sure .env and other secret files cannot be downloaded from the public site.

## References
- **[Secrets Management (OWASP)](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)** — OWASP cheat sheet（Reference）

## Check your site now
Enter a URL and find what is missing before launch, for free.
[Run audit](https://ismyappok.com/en/audit/check)