The vulnerability description explicitly identifies the requireBasicAuth function as the source of a timing side-channel vulnerability due to an unsafe string comparison. To confirm this and analyze the patch, I first identified the commit range between the last vulnerable version (2.0.0-rc.8) and the first patched version (2.0.1-rc.9) by querying the repository tags. Comparing the commits between these two tags revealed a key commit 4e091a6baadb7fe3708f3485b94b85c6457643d3 with the message "fix(basic-auth): use jitter and constant-time string comparison".
Analysis of this commit's diff shows that in the file src/utils/auth.ts, the requireBasicAuth function was modified. The vulnerable code, which used a simple !== comparison for the password, was removed:
- if (opts.password && password !== opts.password) {
- throw autheFailed(event, opts?.realm);
- }
It was replaced with a call to a new timingSafeEqual function, which performs a constant-time comparison to prevent timing attacks:
+ if (
+ (opts.username && !timingSafeEqual(username, opts.username)) ||
+ (opts.password && !timingSafeEqual(password, opts.password)) ||
+ (opts.validate && !(await opts.validate(username, password)))
+ ) {
+ await randomJitter();
+ throw authFailed(event, opts?.realm);
+ }
This directly confirms that requireBasicAuth was the vulnerable function, as it contained the insecure comparison logic that was the root cause of the CVE.