account-enumeration

A sign-in that tells whether an account exists.

Group
Code
Runs
Runs under ur scan: ur scan --rule account-enumeration
Level
warning
Reads
Every file
Fix
None: the safe form depends on what the value is meant to be

Why

A sign-in answers with one message when it finds no account and another when the password is wrong, so whoever tries it learns which email addresses or names have accounts, and can aim guesses at those. Give the same message for both, such as "Invalid email or password".

The fix, as Ur suggests it: give both failures the same message.

For agents

Give a sign-in the same message for an unknown account and a wrong password.

Example

app/models/user.rb
class User < ApplicationRecord
  def self.sign_in(email, password)
    user = find_by_email(email)
    raise "No account for #{email}" unless user
    raise "Incorrect password" unless user.authenticate(password)
    user
  end
end
What Ur prints
$ ur scan --rule account-enumeration
warning[account-enumeration]: a sign-in says "No account for {}" when no account is found but "Incorrect password" for a wrong password, which tells anyone which accounts exist
  --> ./app/models/user.rb:4:5 method `sign_in`
  = hint: give both failures the same message
  = see: CWE-204: Observable Response Discrepancy, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/204.html
scanned 1 file (no framework recognized)
  account-enumeration: 1 high, 0 medium
1 finding and 0 of medium confidence

Try it in the playground →

Source

CWE-204: Observable Response Discrepancy, MITRE (2024-11-19).