1. Authentication
Is this a valid key?
Validates the key exists and hasn’t been revoked
Understanding the security model behind API keys, why they’re used, potential risks, and how the system mitigates threats.
API keys provide a balance between security and usability for programmatic access.
| Method | Pros | Cons | Use Case |
|---|---|---|---|
| API Keys | Simple, stateless, revocable | Static credentials, require careful management | Server-to-server integrations |
| OAuth 2.0 | User-delegated, scoped permissions | Complex flow, requires user interaction | Third-party apps accessing user data |
| JWT Tokens | Stateless, short-lived, signed | Requires token refresh logic | User session authentication |
| Basic Auth | Extremely simple | Username/password in every request | Legacy systems only |
Why API keys win for this platform:
1. Authentication
Is this a valid key?
Validates the key exists and hasn’t been revoked
2. Authorization
Does this key have permission?
Checks role-based access control (RBAC)
3. Rate Limiting
Is this usage pattern legitimate?
Prevents abuse and runaway scripts
Result: Even database administrators cannot retrieve original keys.
X-API-Key headerResult: Timing attacks cannot reveal valid keys.
Unauthorized Access
Only users with valid keys can access the API
Mitigation: Key validation, role-based permissions
Privilege Escalation
Agent keys cannot perform admin operations
Mitigation: Role-based access control (RBAC)
Denial of Service
Runaway scripts can’t exhaust server resources
Mitigation: Rate limiting per key
Data Exfiltration
Limits on how much data can be extracted
Mitigation: Rate limits, audit logging
| Threat | Why Keys Don’t Help | Actual Mitigation |
|---|---|---|
| Key Theft | Stolen key works like the original | Key rotation, secure storage, monitoring |
| Insider Threats | Legitimate users with malicious intent | Audit logging, least privilege, separation of duties |
| Network Sniffing | Keys sent in HTTP headers | HTTPS/TLS encryption (required) |
| Database Breach | Hashes can be cracked offline | Strong hashing (bcrypt), database encryption |
Admin Key Exposure
Credential Stuffing
Rate Limit Bypass
Broker Key Misuse
Logging Sensitive Data
Revoked Key Caching
Creation:
Usage:
Rotation:
Revocation:
Set up alerts for:
| Alert Type | Threshold | Action |
|---|---|---|
| High Error Rate | >10% 4xx/5xx responses | Investigate integration issue |
| Rate Limit Hit | Key hits limit 3+ times/day | Contact integration owner |
| Geographic Anomaly | Requests from unexpected country | Potential key theft |
| After-Hours Usage | Activity outside business hours | Review for automation gone wrong |
| Dormant Key Activity | Unused key suddenly active | Potential compromise |
Similarities:
sk_, pk_ vs. idx_)Differences:
Similarities:
Differences:
Similarities:
Differences:
OAuth 2.0 is the industry standard for user-delegated API access, but it’s overkill for this platform.
sequenceDiagram User->>App: Clicks "Connect to CRM" App->>OAuth Server: Authorization request OAuth Server->>User: Login & grant permissions User->>OAuth Server: Approves OAuth Server->>App: Authorization code App->>OAuth Server: Exchange code for token OAuth Server->>App: Access token App->>API: Request with tokensequenceDiagram Admin->>Dashboard: Create API key Dashboard->>Admin: Returns key Admin->>Integration: Configures key Integration->>API: Request with keyWhen OAuth would be better:
Why API keys suffice:
Potential improvements to the key system: