← Java / Spring · Contents

JAVA-091 / Advanced

Bypassing two-factor authentication (trusting the OTP-stage session)

A07:2021 · CWE-304 Missing Critical Step in Authentication

Why is this a problem?

Post-authentication routes can be accessed without OTP verification.

How to fix it

java
session.setAttribute("PENDING_2FA", user.getId());   // Create the authentication object and replace the session after OTP success

Further reading