API keys scoped to minimum permissions
Why it matters
An API key with full administrative access is a skeleton key: if it leaks — through a log line, a git commit, a compromised developer laptop — the attacker inherits every permission you have. OWASP A01 (Broken Access Control) and NIST AC-6 (Least Privilege) both require limiting credentials to only the operations they need. A Stripe key scoped to charge creation cannot be used to delete customer data or issue refunds. A SendGrid key scoped to sending cannot expose your contact list. PCI-DSS 4.0 Req-7.2 requires that access to system components is appropriately defined and granted — overly broad API keys violate this at the integration layer.
Severity rationale
High because an over-permissioned API key that leaks grants an attacker the same broad access as the application, expanding the blast radius of any credential compromise.
Remediation
Audit each external service's dashboard and create restricted keys with only the permissions your application actually exercises. Document each key's scope in your secrets manager description field.
// src/config/api-keys.ts — one scoped key per service per environment
export const stripeKey = process.env.STRIPE_RESTRICTED_KEY // charges + webhooks only
export const openaiKey = process.env.OPENAI_API_KEY // completions only, no admin
export const sendgridKey = process.env.SENDGRID_MAIL_ONLY_KEY // mail send only
Stripe: Dashboard → Developers → API keys → Create restricted key → select "Charges: Write" and "Webhooks: Read" only. SendGrid: Settings → API Keys → Restricted Access → Mail Send. Generate new restricted keys, update your secrets manager, then revoke the old full-access keys.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Environment Security Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-250 — Execution with Unnecessary Privileges
- owasp:2021 · A01 — Broken Access Control
- nist:rev5 · AC-6 — Least Privilege
- pci-dss:4.0 · Req 7.2 — Access to system components restricted to least privilege
- soc2:2017 · CC6.1 — Logical access security software, infrastructure, and architectures
- soc2:2017 · CC6.3 — Role-based access and least privilege
Taxons
History
- 2026-04-18·v1.0.0·Initial import from environment-security·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.1, CC6.3) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2