Skip to content

Commit af75b8c

Browse files
authored
Merge commit from fork
1 parent 1ab1ea3 commit af75b8c

2 files changed

Lines changed: 315 additions & 4 deletions

File tree

client/src/main/java/org/asynchttpclient/netty/handler/intercept/Redirect30xInterceptor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import static io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION;
4242
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
4343
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
44+
import static io.netty.handler.codec.http.HttpHeaderNames.COOKIE;
4445
import static io.netty.handler.codec.http.HttpHeaderNames.HOST;
4546
import static io.netty.handler.codec.http.HttpHeaderNames.LOCATION;
4647
import static io.netty.handler.codec.http.HttpHeaderNames.PROXY_AUTHORIZATION;
@@ -113,7 +114,9 @@ public boolean exitAfterHandlingRedirect(Channel channel, NettyResponseFuture<?>
113114
boolean schemeDowngrade = request.getUri().isSecured() && !newUri.isSecured();
114115
boolean stripAuth = !sameBase || schemeDowngrade || stripAuthorizationOnRedirect;
115116

116-
if (stripAuth && (request.getRealm() != null || request.getHeaders().contains(AUTHORIZATION))) {
117+
if (stripAuth && (request.getRealm() != null
118+
|| request.getHeaders().contains(AUTHORIZATION)
119+
|| request.getHeaders().contains(COOKIE))) {
117120
LOGGER.debug("Stripping credentials on redirect to {}", newUri);
118121
}
119122

@@ -209,8 +212,14 @@ private static HttpHeaders propagatedHeaders(Request request, Realm realm, boole
209212
headers.remove(CONTENT_TYPE);
210213
}
211214

212-
if (stripAuthorization || (realm != null && (realm.getScheme() == AuthScheme.NTLM
213-
|| realm.getScheme() == AuthScheme.SCRAM_SHA_256))) {
215+
if (stripAuthorization) {
216+
// Cookie is dropped only on the security boundary; the URI-scoped CookieStore re-adds
217+
// any cookies that legitimately match the new target after this method returns.
218+
headers.remove(AUTHORIZATION)
219+
.remove(PROXY_AUTHORIZATION)
220+
.remove(COOKIE);
221+
} else if (realm != null && (realm.getScheme() == AuthScheme.NTLM
222+
|| realm.getScheme() == AuthScheme.SCRAM_SHA_256)) {
214223
headers.remove(AUTHORIZATION)
215224
.remove(PROXY_AUTHORIZATION);
216225
}

0 commit comments

Comments
 (0)