Skip to content

MLE-33480: Bugcrowd: node-client-api: a DIGEST client sends the password in cleartext if the server answers with a Basic challenge - #1134

Merged
vishwach merged 5 commits into
developfrom
MLE-33480
Nov 20, 2026
Merged

vishwach merged 5 commits into
developfrom
MLE-33480

Conversation

@vishwach

@vishwach vishwach commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

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.

…ord in cleartext if the server answers with a Basic challenge
…ord in cleartext if the server answers with a Basic challenge
@vishwach
vishwach marked this pull request as ready for review November 18, 2026 09:56
Copilot AI balanced review requested due to automatic review settings November 18, 2026 09:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
What changed in this PR

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.
lib/​www-authenticate-patched/​www-authenticate.js Validates schemes, selects challenges, and tightens Digest handling.
lib/​www-authenticate-patched/​parsers.js Splits combined challenges and handles malformed headers.
lib/​requester.js Passes the expected scheme and stops requests on authentication errors.

Review effort: Balanced

Comment thread lib/www-authenticate-patched/parsers.js Resolved
…combined WWW-Authenticate headers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Digest challenge selection rejects authentication when an unsupported algorithm precedes a supported one, making success depend on challenge order.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Skip unsupported Digest challenges when a supported one is available

lib/​www-authenticate-patched/​www-authenticate.js:63

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.

1 resolved since last review

Review effort: Balanced

… offered

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the authentication downgrade protection changes.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the authentication-hardening changes.

No open issues 🎉

Review effort: Balanced

if (expected) {
const challenges= parsers.split_challenges(www_authenticate);
const parsedChallenges= challenges.map(challenge => new parsers.WWW_Authenticate(challenge));
const offered= parsedChallenges.map(parsedChallenge =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

}
};

let candidates= [www_authenticate];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@prgs-rsingh prgs-rsingh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

…ord in cleartext if the server answers with a Basic challenge
@vishwach
vishwach requested a review from prgs-rsingh November 19, 2026 10:12
@vishwach
vishwach merged commit 3affaa0 into develop Nov 20, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants