Skip to content

HTTPCLIENT-2414 - Fix Basic auth cache scoping across path prefixes#802

Open
arturobernalg wants to merge 1 commit intoapache:masterfrom
arturobernalg:HTTPCLIENT-2414
Open

HTTPCLIENT-2414 - Fix Basic auth cache scoping across path prefixes#802
arturobernalg wants to merge 1 commit intoapache:masterfrom
arturobernalg:HTTPCLIENT-2414

Conversation

@arturobernalg
Copy link
Member

Preserve AuthExchange pathPrefix on reset to avoid preemptive Authorization reuse outside the protection space.

Copy link

@rPraml rPraml left a comment

Choose a reason for hiding this comment

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

Test looks good and the fix makes sense to me

(But I’m not really deep enough into the topic to know if it could have any other side effects.)

});
}

Assertions.assertEquals(Arrays.asList(401, 200, 401, 200), responseCodes);
Copy link

Choose a reason for hiding this comment

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

Yes, this is the expected result now.

this.state = State.UNCHALLENGED;
this.authOptions = null;
this.authScheme = null;
this.pathPrefix = null;
Copy link

Choose a reason for hiding this comment

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

When I debugged the issue in my code, I come to exactly this place, where the previously set path prefix was cleared.
So I think, not setting pathPrefix = null here will fix the issue.

@arturobernalg arturobernalg requested a review from ok2c February 10, 2026 10:50
Copy link
Member

@ok2c ok2c left a comment

Choose a reason for hiding this comment

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

@arturobernalg It is good that we a have a fix for the defect, but as a side effect the AuthExchange#reset method now kind of resets the state but not quite. This is wrong. conceptually the fix is all right but it need to be moved from the #reset method to the protocol layer.

@arturobernalg arturobernalg force-pushed the HTTPCLIENT-2414 branch 2 times, most recently from 3f06fa0 to 31f81ae Compare February 11, 2026 07:39
@arturobernalg arturobernalg requested review from ok2c and rPraml February 11, 2026 07:41
Preserve AuthExchange pathPrefix on reset to avoid preemptive Authorization reuse outside the protection space.
@arturobernalg
Copy link
Member Author

@arturobernalg It is good that we a have a fix for the defect, but as a side effect the AuthExchange#reset method now kind of resets the state but not quite. This is wrong. conceptually the fix is all right but it need to be moved from the #reset method to the protocol layer.
Agreed; I restored AuthExchange#reset() to fully reset state and move the path-prefix handling into ProtocolExec / AsyncProtocolExec (tests updated accordingly).

responseQueue.stream().map(HttpResponse::getCode).collect(Collectors.toList()));
assertThat(
responseQueue.stream().map(HttpResponse::getCode).collect(Collectors.toList()),
CoreMatchers.equalTo(Arrays.asList(200, 401, 200, 401, 200, 401, 200)));
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg This worries me a little. I want to understand why the behavior has changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@arturobernalg This worries me a little. I want to understand why the behavior has changed.

The expectation in that assertion was effectively relying on the client reusing Basic auth preemptively across unrelated path prefixes within the same context (so it behaved almost host-wide). With my change we now keep preemptive auth scoped to the authenticated path prefix, so when the request moves from /yada/ back to /blah/ it no longer sends Authorization blindly and you see a fresh 401/200 again.

Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg I see. My test case was wrong from the very beginning. The path prefixes of the first and the third requests are different. I overlooked it. Your fix is correct. Please just remove unnecessary code at line 166 in ProtocolExec and line 162 in AsyncProtocolExec

if (targetAuthExchange.getPathPrefix() == null) {
     targetAuthExchange.setPathPrefix(pathPrefix);
}

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.

3 participants