Blog / A02:2021 Cryptographic Failures
A02:2021 · Cryptographic Failures

A keystore that hands back raw private keys isn't one

The whole point of a key vault is that the secret never leaves it. One helper loaded the private bytes and returned them to the caller as a string.

caller passes akey aliashelper loads theprivate key bytesbytes get packedinto a…list is returnedto the callerthe secret leavesthe vaultATTACKER INPUTIMPACTwritten to logs
Attack path · caller passes a key alias → helper loads the private key bytes → bytes get packed into a string list → list is returned to the caller → the secret leaves the vault

The whole point of a key vault is that the secret never leaves it. One helper loaded the private bytes and returned them to the caller as a string.

What goes wrong

A key vault earns its keep by exposing operations and nothing else. You can sign with the key, decrypt with the key, wrap another key. What you should never be able to do is read the key back out. This helper broke that. It took an alias the caller controls, loaded the matching private key, encoded the bytes, and returned them in a list of strings.

Once a private key is a return value it stops being a secret. It lands in logs, in a heap dump, in the body of the next service call, on the screen of whoever is debugging. You can rotate a leaked password in an afternoon. Rotating a leaked signing key means re-issuing everything that key ever vouched for, and hoping nobody kept a copy of the old material.

The pattern

Vulnerable
List<String> getKey(String alias) {
  var entry = keystore.load(alias);
  byte[] raw = entry.privateKeyBytes();
  List<String> out = new ArrayList<>();
  out.add(hex(raw));
  return out;   // the private key just left the vault
}
Hardened
byte[] signWith(String alias, byte[] message) {
  var entry = keystore.load(alias);
  // the key stays inside; only the result crosses out
  return entry.sign(message);
}
// there is no accessor that returns raw key bytes, ever
How the pipeline adjudicated itHELD
ABCDEFGH

Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

If any code path can return raw key material, every caller becomes a place your key can leak from. An attacker doesn't have to break your crypto. They ask the API for the key and walk away with it.

The fix is a boundary, not a patch. Wrap the key so callers get verbs (sign, decrypt, wrap) and never the noun. If a getter for private bytes exists anywhere, assume someone will call it in production.

Check your own code