Whether a new key demands user authentication is set by a boolean the caller passes. Send false and the key lands in the keystore with no auth binding at all.
What goes wrong
The most important security decision about a key is made in one line, and this code lets the caller make it. A key's security properties are locked in the moment it is created, and one of the biggest is whether using it demands user authentication. Here that decision is delegated to the caller through a boolean parameter. Pass true and the key is gated by biometric or device credential. Pass false and it is not.
Once a key is generated without the authentication requirement, it stays that way for its whole life. Anything that can reach the key can use it, no prompt, no re-auth. If any path lets an attacker or a careless caller choose false, the sensitive operations that key protects are available without the user ever being asked. A security property this important should not be a parameter.
The pattern
function generateKey(alias, requireAuth) {
const spec = keySpec(alias)
// requireAuth comes straight from the caller
spec.setAuthRequired(requireAuth)
keystore.generate(spec) // false leaves the key ungated
}function generateKey(alias) {
const spec = keySpec(alias)
spec.setAuthRequired(true) // fixed policy, not an argument
spec.setAuthValidityWindow(SHORT) // re-auth per use
keystore.generate(spec)
}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.
Why it matters to you
Keys outlive the request that made them. A key born without an authentication requirement is a standing liability no later check can fully repair, because the constraint has to be baked in at creation. When the constraint is optional, someone eventually ships the option that turns it off.
Decide your key policy in one place and make it non-negotiable for anything sensitive. If different keys genuinely need different rules, gate that choice behind a trusted policy layer, not a flag any caller can set.
Check your own code
- Search for an authentication-required setting driven by a variable or parameter instead of a constant.
- Confirm sensitive keys are created with user authentication required and a sane validity window.
- Remove caller control over key security properties; centralize the policy.
- Audit existing keystore entries for any created without an authentication requirement.