|
41 | 41 | import static io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION; |
42 | 42 | import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; |
43 | 43 | import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; |
| 44 | +import static io.netty.handler.codec.http.HttpHeaderNames.COOKIE; |
44 | 45 | import static io.netty.handler.codec.http.HttpHeaderNames.HOST; |
45 | 46 | import static io.netty.handler.codec.http.HttpHeaderNames.LOCATION; |
46 | 47 | import static io.netty.handler.codec.http.HttpHeaderNames.PROXY_AUTHORIZATION; |
@@ -113,7 +114,9 @@ public boolean exitAfterHandlingRedirect(Channel channel, NettyResponseFuture<?> |
113 | 114 | boolean schemeDowngrade = request.getUri().isSecured() && !newUri.isSecured(); |
114 | 115 | boolean stripAuth = !sameBase || schemeDowngrade || stripAuthorizationOnRedirect; |
115 | 116 |
|
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))) { |
117 | 120 | LOGGER.debug("Stripping credentials on redirect to {}", newUri); |
118 | 121 | } |
119 | 122 |
|
@@ -209,8 +212,14 @@ private static HttpHeaders propagatedHeaders(Request request, Realm realm, boole |
209 | 212 | headers.remove(CONTENT_TYPE); |
210 | 213 | } |
211 | 214 |
|
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)) { |
214 | 223 | headers.remove(AUTHORIZATION) |
215 | 224 | .remove(PROXY_AUTHORIZATION); |
216 | 225 | } |
|
0 commit comments