An API key is a credential that provides access to personal data. When it is compromised, the attacker gains access to whatever personal data the key can reach. Under GDPR, KVKK, CPRA, and FADP, that is a reportable security incident. The notification obligations, potential fines, and reputational consequences follow directly from how the key was stored, how quickly the compromise was detected, and how effectively access was revoked.
API key security is therefore not a security-team concern that happens to touch compliance. It is a core privacy compliance control — one that regulators evaluate when investigating data incidents and one that auditors request evidence for during compliance assessments.
What a Compromised API Key Triggers
The regulatory consequences of an API key breach depend on what data the key could access, how many records were exposed, and whether the organization had appropriate technical measures in place. In the worst case:
- GDPR: Supervisory authority notification within 72 hours if the breach is likely to result in risk to data subjects. Individual notification if the risk is high. Maximum fine: €20M or 4% of global annual turnover.
- KVKK: Notification to the Personal Data Protection Board and data subjects. Administrative fines plus potential criminal liability for responsible individuals.
- CPRA: Statutory damages of $100–$750 per consumer per incident for breaches of non-encrypted personal information. CPPA enforcement action for systemic failures.
- FADP: Notification to the FDPIC and affected data subjects when breach may lead to high risk. Criminal sanctions up to CHF 250,000 for responsible individuals for intentional violations.
The key question regulators and plaintiffs' lawyers ask: did the organization have appropriate technical measures in place? Storing API keys in plaintext is not an appropriate technical measure. It is an elementary failure that eliminates the "we took reasonable precautions" defence.
The Minimum: Hash Before Storage
API keys must be hashed before storage. The plaintext key is generated and displayed once, at creation. The system stores only the hash. When the consumer presents the key in an API request, the system hashes the presented value and compares against the stored hash.
The choice of hashing algorithm matters:
- bcrypt or Argon2: Preferred for key storage. Computationally expensive by design, making brute-force attacks against the hash infeasible. Argon2 is the current recommendation from the Password Hashing Competition.
- SHA-256 with salt: Acceptable when key length is sufficient (32+ random bytes) to make the hash space too large for precomputation attacks. Fast hashing algorithms (MD5, SHA-1) are not acceptable — they are too fast for this purpose.
- Avoid: Reversible encoding (base64), symmetric encryption with a static key, or any scheme where the plaintext can be recovered from the stored value.
The practical implication: your API key verification path computes a hash on every request. For high-throughput APIs, benchmark the hashing algorithm's performance and cache hash-to-permission lookups where the security model permits. Argon2 can be tuned for the performance/security tradeoff, but any tuning that makes brute-force practical defeats the purpose.
Kubernetes Recipes
A practical guide for container orchestration and deployment by Grzegorz Stencel & Luca Berton (Apress).
Watch on Skillshare →Key Scoping and Least Privilege
GDPR Article 32, KVKK Article 12, and FADP's privacy-by-design principle all require that access to personal data be limited to what is necessary. For API keys, this translates to scoped permissions:
- Keys should carry permissions, not open-ended access to all resources
- A key for reading user-facing content should not have access to personal data exports
- A key for analytics should not have access to write operations on personal data
- Sensitive personal information (CPRA's category) and special category data (GDPR Article 9) should require separately issued keys with explicit access
Scoping also limits breach impact. A compromised key with read-only access to product data is a different compliance event than a compromised key with full access to customer personal data. The former may not trigger notification obligations; the latter almost certainly does.
Rotation, Expiry, and Revocation
Static keys that never expire are a compliance liability. Every regulation's "appropriate technical measures" requirement includes controls that limit the window of exposure from a compromised credential:
- Mandatory expiry: Keys should have a configurable maximum lifetime. Long-lived keys (more than 90 days without rotation) increase exposure window and complicate the "when did the compromise occur" question during breach investigation.
- Self-service rotation: Key holders should be able to rotate their keys without creating a support ticket. Friction in the rotation process means rotation happens less frequently than it should.
- Immediate revocation: When a key is suspected compromised, revocation must take effect immediately — within seconds, not the next cache invalidation cycle. Plan for cache TTLs in your key validation path and ensure revocation propagates faster than the cache.
- Audit log of all key lifecycle events: Creation, rotation, revocation, and deletion must be logged with timestamps and the identity of the actor. This log is evidence in a breach investigation and a compliance audit.
Operationalizing ML Models: MLOps for Scalable AI
Turn ML prototypes into robust, scalable systems using real-world tools. In collaboration with Starweaver.
Start on Coursera →Detection: Knowing When a Key Is Compromised
Prompt detection limits breach scope, limits regulatory exposure, and is itself a demonstrable technical control. What to monitor:
- Volume anomalies: A key that normally makes 100 requests per hour making 10,000 per hour is suspicious. Statistical anomaly detection on per-key request volume catches bulk exfiltration patterns that static rate limits miss.
- Geographic anomalies: A key normally used from Frankfurt suddenly making requests from Singapore warrants investigation. Not necessarily a breach, but a signal worth examining.
- Endpoint anomalies: A key normally used for product catalog access suddenly requesting user profile exports is a stronger signal than volume alone.
- Time-of-day anomalies: Requests at 3am from a key used exclusively during business hours.
Detection feeds notification timelines. GDPR's 72-hour clock starts when the organization "becomes aware" of the breach. Demonstrating that anomaly detection flagged the incident promptly — and that the response was immediate — is significantly better than discovering a breach in a third-party report weeks later.
Rate Limiting as a Containment Control
Per-key rate limits are both an abuse prevention control and a privacy compliance control. They limit the volume of personal data that any single compromised credential can access in a time window:
- Implement rate limits that reflect legitimate use patterns — a key that legitimately needs 1,000 requests per minute should be limited to something above that, not to 100
- Apply stricter limits to endpoints that return personal data than to endpoints returning non-personal data
- Rate limit errors should not reveal whether the limit was triggered by volume, geographic anomaly, or active investigation — generic "rate limit exceeded" responses prevent adversarial probing of the detection logic
- Document rate limits in your technical controls register as a privacy protection measure
EU AI Act Compliance Checklist
40-point checklist covering risk classification, data governance, transparency, and human oversight. Based on the official regulation.
Get Free Checklist →The Compliance Evidence Package
When a regulator investigates a key-related incident, or an auditor evaluates your API security controls, the evidence package for API key management should include:
- Documentation of the hashing algorithm and parameters used for key storage
- Architecture documentation showing keys are not stored in plaintext at any point
- Key lifecycle policy — maximum lifetime, rotation frequency, revocation procedure
- Audit log samples demonstrating key events are captured
- Rate limiting configuration and the rationale for chosen limits
- Anomaly detection configuration and recent alert examples
- Incident response procedure for suspected key compromise — who is notified, what is revoked, when does regulatory notification assessment begin
This documentation does not prevent incidents. But in the aftermath of an incident, it is the difference between demonstrating that you had appropriate technical measures and being unable to show what measures existed. Under GDPR Article 32, the burden is on the controller to demonstrate appropriateness. Under FADP, personal liability for responsible individuals means the individuals who made technical decisions have a direct interest in that documentation existing.
Related Solution
Need GDPR-compliant AI infrastructure? We design architectures that satisfy data residency, DPIAs, and right-to-erasure from day one.
Learn about our GDPR-compliant AI infrastructure →
Luca Berton
