Bypassing Email Verification in Node.js with a Simple Logic Flaw
The account verification endpoint compared the stored token with the supplied token using loose equality and did not check that a token existed. When the stored token was null, sending a null token made the comparison succeed and the account was marked as verified without any real token.
medium.com
Published on medium.com
While I was working on a simple register system in Node.js I wanted to understand how the email verification works in the backend.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code used loose equality (==) and did not reject a missing or null stored token, so null matched null.
Impact
An attacker could bypass email verification and create verified accounts without owning the email address, and any feature that depends on verified users could be abused.
What the attacker needed
A stored verification token that is null; ability to send a verification request
The fix
The code should use strict comparison, reject a missing stored token, and ideally look up the user by both email and token in the query.
How it was found
- Register an account so a verification token is generated, or find an account whose stored token is null.
- Send a request to the verification endpoint with the victim's email and a null token.
- The loose comparison of null and null succeeds and the account is marked verified.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When a website checks whether two values are the same, the programming language can treat certain empty values as equal to each other. Here the stored verification token was empty (null), and the attacker sent an empty token too, so the check passed. That let someone mark an account as verified without ever receiving the email.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.