API Keys Have Scoped Permissions
Why it matters
API keys without scope restrictions grant the same access as the owner's full session — a compromised key is equivalent to a compromised account. CWE-285 (Improper Authorization) and CWE-284 cover the failure to limit what an API key can do. OWASP A01 (Broken Access Control) flags credential over-privilege as a primary risk. NIST 800-53 AC-6 (Least Privilege) and IA-3 (Device Identification) require that credentials be limited to their intended purpose. A read-only integration that holds a full-permission key can delete all user data, initiate payment changes, or export sensitive records — damage that scoped keys would prevent.
Severity rationale
High because a single compromised full-permission API key exposes the entire account, whereas a scoped key limits the blast radius to the permitted operations.
Remediation
Add a scopes array to the API key model and enforce scope checks during request handling. The key is only valid for operations that match its declared scopes.
// prisma/schema.prisma
model ApiKey {
id String @id @default(cuid())
userId String
scopes String[] // e.g., ['read:posts', 'write:posts']
}
// lib/auth/api-key.ts
export async function validateApiKey(key: string, requiredScope: string) {
const apiKey = await db.apiKey.findUnique({ where: { key } });
if (!apiKey || !apiKey.scopes.includes(requiredScope)) return null;
return apiKey;
}
When generating keys, let users select which scopes to grant — this enforces least privilege at the point of creation rather than relying on callers to self-limit.
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 Authorization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-285 — Improper Authorization
- cwe · CWE-284 — Improper Access Control
- owasp:2021 · A01
- nist:rev5 · AC-6
- nist:rev5 · IA-3 — Device Identification and Authentication
- soc2:2017 · CC6.3 — Role-based access and least privilege
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-authorization·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.3) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2