Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
Expand Down Expand Up @@ -84,6 +85,16 @@ public boolean isRedirected(final HttpRequest request, final HttpResponse respon
}
}

@Override
public boolean isRedirectAllowed(
final HttpHost currentTarget,
final HttpHost newTarget,
final HttpRequest redirect,
final HttpContext context) {
// Always allow, regardless of sensitive headers
return true;
}

protected boolean isRedirectable(final String method) {
for (final String m : REDIRECT_METHODS) {
if (m.equalsIgnoreCase(method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import org.apache.hc.client5.http.classic.methods.HttpHead;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -68,6 +71,24 @@ void testIsRedirectedWithNonRedirectMethod() {
testIsRedirected(new HttpPut("/put"), false);
}

@Test
void testIsRedirectAllowedAlwaysTrue() {
final LaxRedirectStrategy strategy = new LaxRedirectStrategy();
final HttpContext context = mock(HttpContext.class);
final HttpHost current = new HttpHost("http", "localhost", 80);
final HttpHost next = new HttpHost("http", "example.com", 80);
// Create a request with an Authorization header
final HttpRequest request = new HttpGet("/test");
request.addHeader(HttpHeaders.AUTHORIZATION, "Bearer token");

// Even with sensitive headers and target change, LaxRedirectStrategy should allow it
assertTrue(
strategy.isRedirectAllowed(current, next, request, context),
"LaxRedirectStrategy should always allow redirects regardless of sensitive headers"
);
}


private void testIsRedirected(final HttpRequest request, final boolean expected) {
final LaxRedirectStrategy strategy = new LaxRedirectStrategy();
final HttpResponse response = mock(HttpResponse.class);
Expand Down
Loading