CWE-305 describes an authentication algorithm that is sound on paper, yet the implemented mechanism can be bypassed because of a separate weakness that is primary to the authentication error. The bypass is a symptom. The cause lives somewhere else in the code.
How it happens
The observed examples in MITRE show how plain these causes can be:
- CVE-2002-1374: the provided password is compared only against the first character of the real password.
- CVE-2000-0979: the password is not properly checked, so remote attackers bypass access controls by sending a 1-byte password that matches the first character of the real password.
- CVE-2001-0088: a chain in which forum software does not properly initialize an array, inadvertently setting the password to a single character, so attackers easily guess the password and gain administrative access.
Notice that none of these involve a broken cryptographic algorithm. A length bug, an off-by-one in a comparison loop, or an uninitialized variable did the damage.
/* Vulnerable: compares only as many bytes as the user supplied */
if (strncmp(supplied, stored, strlen(supplied)) == 0) {
grant_access();
}
A one-character input that matches the first character of the stored password passes.
What an attacker gains
The listed consequence is bypass of the protection mechanism, which usually means access as a valid user, sometimes an administrator.
How to find it
The record has no detection methods. Test the edges: empty password, one-character password, a prefix of the real password, a very long password, and unusual characters. All must fail. Code review should look closely at every comparison on a credential and at initialization of the buffers that hold one.
How to fix it
- Compare the full value, and compare lengths before content.
- Use the language's vetted password verification function instead of a hand-written loop.
- Initialize all buffers and arrays that feed an authentication decision.
- Add the edge cases above to the automated test suite so they cannot return unnoticed.
Quick check
Why is this a different weakness from a bad algorithm?
The algorithm was fine. A separate implementation flaw, like a truncated comparison, let attackers go around it.