API Keys and Secrets Management for Startups: Stop Leaking Credentials Before It Costs You
This is general information, not legal, tax, financial, medical or security advice. Rules and prices change, so confirm details with the official sources linked below or a qualified professional.
Secrets management for a startup means keeping API keys, database passwords, tokens and private keys out of source code and chat, storing them in encrypted environment variables or a secrets manager, giving each environment and service its own least-privilege credentials, turning on leak detection such as GitHub push protection, and rotating keys on a schedule and immediately after any exposure. Done early, it takes a few hours. Done after a leak, it can take days and a large cloud bill.
Startups move fast, share access widely and integrate dozens of APIs (payments, email, AI models, analytics). Every one of those integrations is a credential that someone could leak.
This is general information, not professional security advice.
Key takeaways
- Never put secrets in code, tickets, chat or docs. Assume anything committed to Git is permanent.
- Use encrypted environment variables or a secrets manager for anything deployed.
- Separate keys per environment and service, each with the minimum permissions it needs.
- Turn on leak prevention. GitHub push protection blocks pushes containing recognized secrets.
- Have a leak playbook: revoke, rotate, remove, review. This mirrors OWASP's incident guidance.
What counts as a secret
| Secret type | Examples | Impact if leaked |
|---|---|---|
| Cloud credentials | AWS, Google Cloud, Azure keys; service account files | Data theft, resource abuse, large bills |
| Database credentials | Postgres connection strings, Supabase service role key | Full data access, deletion |
| Payment API keys | Stripe secret keys, webhook signing secrets | Refunds, data exposure, fraud |
| AI/LLM API keys | Model provider keys | Unauthorized usage charged to you |
| Platform tokens | Shopify Admin API tokens, GitHub tokens | Store or code modification |
| Email/SMS provider keys | Transactional email or messaging APIs | Spam or phishing sent from your domain |
| Signing keys | JWT secrets, SSH keys, TLS private keys | Impersonation, session forgery |
A useful rule: if a value lets someone act as your company or your user, it's a secret, even if the provider calls it a "token" or "ID."
Where secrets leak
- Git commits, including old branches and history, even in private repositories
- Front-end code: any key shipped to a browser or mobile app is public by definition
- Logs and error trackers that capture request headers or environment dumps
- Chat and tickets where someone pasted a key "just for a minute"
- Screenshots and screen shares during demos
- CI/CD logs that echo environment variables
- Former team members and contractors who kept copies
GitHub's documentation notes that its secret scanning examines the entire Git history on all branches, which shows why deleting a file in a later commit doesn't remove the risk.
The basics every startup should implement
1. Keep secrets out of code
- Add environment files (for example
.env,.env.local) to.gitignorefrom the first commit. - Commit an example file with placeholder values so new developers know what's needed.
- Load configuration from environment variables or a secrets manager at runtime.
2. Never expose server secrets to the client
Anything bundled into front-end JavaScript or a mobile app can be extracted. Use publishable or restricted keys designed for client use, and route privileged calls through your backend. In frameworks like Next.js, be careful with environment variable prefixes that deliberately expose values to the browser.
3. Use a proper store for deployed secrets
| Option | Good for | Watch out for |
|---|---|---|
| Hosting platform environment variables (Vercel, Netlify, Render, etc.) | Small apps, simple deployments | Who on the team can read production values; per-environment scoping |
| Cloud secret managers (AWS, Google Cloud, Azure) | Apps on that cloud; rotation and IAM integration | Cost per secret and API call; IAM complexity |
| Dedicated secrets platforms | Multi-cloud teams, many services | Another vendor to secure |
| Password manager | Human-used credentials, break-glass keys | Not designed for app runtime access |
OWASP's Secrets Management Cheat Sheet recommends centralizing and standardizing secrets management, applying access control, automating rotation and auditing access.
4. Least privilege and separation
- One key per service and environment. Production keys never appear in development.
- Scope permissions narrowly. Use restricted API keys where providers offer them.
- Separate human and machine access. People sign in with SSO and MFA; services use their own credentials.
- Limit who can read production secrets, and review that list when people leave.
5. Turn on leak prevention and detection
- GitHub push protection blocks pushes that contain recognized secrets and explains why. Push protection for users is enabled by default on GitHub.com and stops pushes of secrets to public repositories. Repository-level push protection requires GitHub Secret Protection.
- Secret scanning finds secrets already in your history.
- Pre-commit hooks with a secret scanner catch mistakes before they leave a laptop.
- Provider alerts and spending limits on cloud and AI accounts limit the cost of abuse.
6. Rotate and expire
OWASP recommends that secrets exist only as long as necessary, rotate often, support automatic rotation, be visible only to those who need them, be revocable, and never be logged. Prefer short-lived credentials (temporary tokens, workload identity, OIDC from CI to cloud) over long-lived static keys wherever providers support them.
Secrets in AI features and agent workflows
AI features add a new class of leak. Keep these rules in mind when you wire up model providers, voice agents or automation tools:
- Never paste keys into prompts or let a model see raw credentials. Logs of prompts and responses may be stored by you or the provider.
- Give agents scoped, revocable credentials, not your personal admin token. If an agent only needs to read orders, don't give it write access to payments.
- Proxy model calls through your backend, so the provider key never reaches a browser or mobile app.
- Set per-key usage limits and alerts with each AI provider so a leaked key can't run up an unbounded bill.
- Review third-party automation tools that store your API keys, and remove connections you no longer use.
Step-by-step: a one-day secrets cleanup
- Inventory every secret: list each API, database and token, which services use it and who can see it.
- Scan your repositories with GitHub secret scanning or an open-source scanner, including full history.
- Rotate anything found in code or chat, prioritizing cloud, database and payment keys.
- Move secrets into your platform's encrypted variables or a secrets manager, separated by environment.
- Replace broad keys with restricted ones where the provider supports scopes.
- Enable push protection and a pre-commit scanner for every developer.
- Scrub logs and CI output of secret values; enable masking.
- Set spending caps and usage alerts on cloud and AI provider accounts.
- Document ownership: who can rotate each secret and how.
- Add secrets to offboarding: rotate what departing people could access.
When a secret leaks: the response playbook
OWASP's incident guidance for secrets centers on rapid containment:
- Revoke the exposed key immediately. Don't wait to confirm abuse.
- Rotate to a new key and deploy it, ideally through an automated process.
- Remove the secret from wherever it was exposed, including code and logs. Rewriting Git history can remove it from the repository but breaks links and forks, so revocation must come first.
- Review provider logs and billing for unauthorized use during the exposure window.
- Notify affected parties if customer data may have been accessed, following what to do after a data breach.
- Learn: add a test, hook or policy that prevents the same mistake.
From experience. Working daily with Next.js, Supabase, Vercel and LLM integrations, and building voice AI on LiveKit at Femma AI, I treat every new integration as a new secret with an owner, a scope and a rotation plan. Setting that up at the start of a project takes minutes; untangling it later is far slower.
Secrets management checklist
- [ ] All secrets inventoried with owners
- [ ] No secrets in repositories (including history), tickets or chat
- [ ]
.envfiles ignored by Git; example file committed - [ ] No server secrets in front-end or mobile code
- [ ] Production secrets in encrypted platform variables or a secrets manager
- [ ] Separate keys per environment and service; least-privilege scopes
- [ ] Push protection and secret scanning enabled; pre-commit scanner installed
- [ ] Secrets masked in logs and CI output
- [ ] Spending limits and usage alerts on cloud and AI accounts
- [ ] Rotation schedule set; offboarding includes secret rotation
- [ ] Leak playbook written and known to the team
Next steps
- Run a secret scan across all repositories today and rotate anything it finds.
- Move production secrets into your hosting platform's encrypted variables or a secrets manager this week.
- Enable push protection and add a pre-commit scanner to your developer setup.
- Protect human access with 2FA and a team password manager, and review app tokens on your Shopify or WordPress site.
- Preparing for investment or acquisition? Secrets handling is a standard item in our technical due diligence reviews, and our fractional CTO service can set it up properly.
Sources
- OWASP, Secrets Management Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
- GitHub Docs, About push protection: https://docs.github.com/en/code-security/secret-scanning/introduction/about-push-protection
- GitHub Docs, About secret scanning: https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning
- NIST SP 1300, CSF 2.0 Small Business Quick-Start Guide: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.1300.pdf
- CISA, #StopRansomware Guide (cloud credentials and backups): https://www.cisa.gov/stopransomware/ransomware-guide
Frequently asked questions
Where should a startup store API keys?
Not in source code, chat messages or shared documents. For local development, use environment files that are excluded from version control. For deployed apps, use your hosting platform's encrypted environment variables or a dedicated secrets manager. Give each environment (development, staging, production) its own keys, and restrict who can read production values.
What should I do if I accidentally commit an API key to GitHub?
Treat it as compromised, even if the repository is private or you deleted the commit. OWASP's guidance is to revoke the exposed key immediately, rotate to a new one, and remove the secret from the exposed system, including code and logs. Then check the provider's logs for unauthorized use. Rewriting Git history can help but has side effects.
Does GitHub detect leaked secrets automatically?
GitHub offers secret scanning and push protection. Push protection blocks pushes that contain recognized secrets before they reach the repository. Push protection for users is enabled by default on GitHub.com and stops you from pushing secrets to public repositories. Repository-level push protection for private repositories requires GitHub Secret Protection, a separate GitHub product.
How often should API keys be rotated?
Rotate immediately whenever a key may have been exposed or when someone with access leaves, and on a regular schedule for high-value keys. OWASP recommends that secrets exist only as long as necessary, rotate often, and have a method for automatic rotation. Short-lived, automatically issued credentials are better than long-lived static keys where providers support them.
Is a .env file secure?
A .env file is acceptable for local development if it is excluded from version control, never shared over chat or email, and contains only development keys. It is not a production secrets strategy. In production, use your platform's encrypted environment variables or a secrets manager with access control, audit logs and rotation support.