You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MLE-33480: Bugcrowd: node-client-api: a DIGEST client sends the password in cleartext if the server answers with a Basic challenge - #1134
Prevents an HTTP authentication downgrade vulnerability. Previously, when a client was configured with authType: 'digest', receiving a 401 Unauthorized challenge with WWW-Authenticate: Basic ... caused the client to silently downgrade and send cleartext credentials in an Authorization: Basic header.
Changes
Enforced Fail-Closed Scheme Validation: In lib/requester.js (challengeRequest), added a case-insensitive check to ensure the challenged authentication scheme matches the client's configured authType.
Immediate Error Emission: Emits an explicit error if a downgrade (e.g. server requests Basic when client is configured for Digest) is attempted, terminating the request before credentials can be sent.
Automated Tests: Added unit tests in test-basic/ using a mock HTTP server returning a 401 Basic challenge to assert that a digest client errors out and never transmits an Authorization: Basic header.
Verification
Verified against a mock HTTP 401 Basic server: request fails immediately without credential leakage.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The challenge-boundary parser misses bare and token68 authentication schemes, allowing subsequent challenges to remain attached to a valid Digest offer and cause authentication failures.
This PR hardens the Node.js client’s HTTP authentication to prevent a Digest-configured client from sending Basic credentials in response to a server challenge.
Changes:
Enforces the configured authentication scheme and stops requests when authentication validation fails.
Adds multi-challenge selection, case-insensitive scheme handling, and stricter Digest validation.
Adds mock-server regression tests for downgrade rejection, error handling, and successful authentication.
File
Description
test-basic/auth-downgrade-test.js
Adds authentication security and compatibility tests.
When a server offers Digest ... algorithm=SHA-256 followed by Digest ... algorithm=MD5, indexOf selects the first Digest challenge and authentication fails with Unsupported Digest algorithm: SHA-256, despite a supported Digest challenge being available. Reversing the same challenges succeeds. Please select a usable challenge within the configured scheme and reject only when none is supported, without falling back to Basic.
The reason will be displayed to describe this comment to others. Learn more.
new parsers.WWW_Authenticate(challenge) runs parse_params(), which requires key=value pairs and clears this.scheme = '' whenever parse_params() returns an error.
In the test Negotiate YWJj==, parse_params() only succeeded by coincidence because YWJj== contains = (which it parsed as key: "YWJj", value: "="). If a server returns a token68 challenge without = padding (e.g., WWW-Authenticate: Bearer eyJhbGciOiJIUzI1NiJ9.e30.sig or WWW-Authenticate: Negotiate YWJj), parse_params() fails with 'Unexpected end of www-authenticate value.' and wipes parsedChallenge.scheme to ''.
Consequently, offered loses the scheme name and the client reports: Authentication failed: Unexpected end of www-authenticate value. instead of: Authentication failed: Server requested BEARER authentication, but the client is configured for DIGEST.
Consider extracting the scheme token (challenge.match(ParseAuth)) before running parse_params() so non-key-value schemes (Bearer , Negotiate ) are still accurately identified in the mismatch error.
The reason will be displayed to describe this comment to others. Learn more.
parsers.split_challenges(www_authenticate) is only called inside if (expected). If the authenticator is initialized without options.expectedScheme and receives a combined multi-challenge header (e.g. Basic realm="a", Digest realm="b", nonce="n", qop="auth"), candidates remains the unsplit string [www_authenticate] and configure() fails in parse_params(). Splitting challenges unconditionally before filtering by expected would handle combined headers in both modes.
The reason will be displayed to describe this comment to others. Learn more.
Solid protection against both Basic and RFC 2069 qop-less Digest downgrades. Left two inline comments in www-authenticate.js regarding token68 challenges without = padding (like Bearer ) being misreported as malformed headers instead of scheme mismatches, and splitting combined challenges when expectedScheme is omitted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents an HTTP authentication downgrade vulnerability. Previously, when a client was configured with
authType: 'digest', receiving a401 Unauthorizedchallenge withWWW-Authenticate: Basic ...caused the client to silently downgrade and send cleartext credentials in anAuthorization: Basicheader.Changes
lib/requester.js(challengeRequest), added a case-insensitive check to ensure the challenged authentication scheme matches the client's configuredauthType.test-basic/using a mock HTTP server returning a401 Basicchallenge to assert that adigestclient errors out and never transmits anAuthorization: Basicheader.Verification