Weak or Non-Expiring API Keys
API keys are short, predictable or derived from known values, or never expire and cannot easily be rotated, so a guessed or leaked key gives lasting access to the API.
| Severity | Medium |
| CVSS 3.1 | 4.8 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N Open in the calculator |
| CVSS 4.0 | 6.3 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-1391: Use of Weak Credentials |
| OWASP Top 10 | A07:2025 Authentication Failures |
| MITRE ATT&CK | T1550.001 Application Access Token, T1110 Brute Force |
| Category | Cryptographic Failures |
Description
API keys authenticate applications and integrations, and are often sent with every request and kept in many places: configuration files, scripts, CI/CD pipelines, mobile applications and partners' systems. The keys issued by the application are weak in one or more of these ways:
- they are short, sequential, or derived from known values such as a user ID, email address or timestamp (for example a hash of the account's email address), so an attacker can calculate or guess valid keys for other accounts and use the API as them;
- they have no expiry date and there is no practical way to rotate them, so a key issued years ago still works, and any key that leaks through code, logs, a former member of staff or a third party gives lasting access, often to everything the account can do, while the organisation may not know who holds it;
- a single key is shared by many clients or users, or grants full access to the account regardless of what each client needs;
- they are stored on the server in plain text, so a copy of the database yields every working key.
The impact depends on how a key could be obtained and on its permissions, and is higher for guessable keys and for keys with administrative or cross-tenant access. The weakness is identified by generating several keys and comparing their length, character set and structure for patterns or a relationship to account data, by decoding keys that appear encoded, by checking whether a key that has been regenerated or deleted still works, and by reviewing the expiry, scoping and rotation options the platform offers. Source code review shows how keys are generated and stored.
Remediation
Issue keys that are random, scoped, stored safely and replaceable:
- Generate keys from at least 128 bits, and preferably 256 bits, of a cryptographically secure random number generator, and give them no meaning. A fixed, recognisable prefix helps secret scanning tools detect leaked keys.
- Store only a hash of each key on the server. Because a random key has far more entropy than a password, a single SHA-256 hash is sufficient, and the full key is shown to its owner once, at creation.
- Issue a separate key for each client or integration, scoped to the permissions and, where possible, the source addresses it needs.
- Give keys an expiry date, support more than one active key so that they can be rotated without downtime, and let owners revoke keys immediately. Revoke keys when staff or suppliers leave.
- Log the use of each key and alert on unusual activity, such as use from new locations.
- For machine-to-machine access, consider short-lived tokens from an OAuth client credentials flow instead of static keys.
Replace existing weak keys and revoke the old ones once clients have moved. Confirm the fix by checking that new keys show no pattern, that they expire, and that revoked and rotated keys are rejected.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.