The Password Reset Sent to a Second Address — Bug Hunt
Modelled on GitLab CVE-2023-7028, disclosed in January 2024 with the maximum CVSS score of 10.
- Language: JavaScript
- Layer: Backend
- Difficulty: Hard
- Concepts: Security, Auth, Validation
- Modelled on: GitLab · CVE-2023-7028
- Visible tests: a normal reset goes to the account's address; an array of addresses is refused
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical (account takeover))
- Ticket: BUG-GL7028
- Reported by: bug bounty
- Time to fix: 35 minutes, the target for a hard incident
Failing checks on the shipped build
- an array of addresses is refused — expected {"ok":false,"error":"invalid_email"} but got {"ok":true}
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Modelled on GitLab CVE-2023-7028, disclosed in January 2024 with the maximum CVSS score of 10. The password-reset form's email parameter could carry more than one address, and GitLab sent the reset link to all of them — including an address the attacker controlled that had never been verified on the account. Supplying the victim's address alongside one's own was enough to take over the account (unless it had two-factor authentication). The bug had been introduced by a change to email handling in GitLab 16.1 in May 2023.
This reconstruction's reset.js accepts a string or an array, finds the account through any listed address, and mails every address it was given.
Fix requestReset so the link can only ever go to the account's own verified address.
Bug report
BUG-GL7028 · Priority: Critical (account takeover) · Reported by: bug bounty
requestReset(params, users, mailer, makeToken):
- params.email must be a single string; an array, object, number or missing value -> { ok: false, error: "invalid_email" } and nothing is sent
- the string is matched against user.email ignoring case and surrounding whitespace
- if it matches a user whose emailVerified is true, send exactly ONE mail: mailer.send(user.email, makeToken(user.id)) — to the address stored on the account, never to the spelling the request used
- matched-but-unverified or unknown addresses send nothing
- every well-formed request answers { ok: true } (no account enumeration)
Observed: email[]=victim@corp.example&email[]=attacker@evil.example mails the victim's reset token to the attacker.
Logs
[reset] user=1 token issued; mailed to victim@corp.example, attacker@evil.exampleThe code as shipped
src/accounts/reset.js (editable)
function findByEmail(users, email) {
for (var i = 0; i < users.length; i++) {
if (users[i].email === email) return users[i];
}
return null;
}
// Sends a password-reset link. Answers { ok: true } whether or not the
// address is known, so the endpoint cannot be used to discover accounts.
exports.requestReset = function (params, users, mailer, makeToken) {
var emails = [].concat(params.email);
var user = null;
for (var i = 0; i < emails.length && !user; i++) user = findByEmail(users, emails[i]);
if (!user) return { ok: true };
var token = makeToken(user.id);
emails.forEach(function (to) { mailer.send(to, token); });
return { ok: true };
};
Read-only context: src/accounts/fixtures.js.
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.