Skip to content

fix(http-client-vertx): resolve relative redirect Location against the request URI (#1142) - #1162

Open
chopmob-cloud wants to merge 2 commits into
a2aproject:mainfrom
chopmob-cloud:fix/vertx-resolve-relative-redirect-location-1142
Open

chopmob-cloud wants to merge 2 commits into
a2aproject:mainfrom
chopmob-cloud:fix/vertx-resolve-relative-redirect-location-1142

Conversation

@chopmob-cloud

Copy link
Copy Markdown

Summary

Fixes #1142. The Vert.x client's opt-in redirect following passed the redirect Location straight to webClient.getAbs(location) (301/302/303) and postAbs(location) (307/308), so a relative Location (e.g. /collect, permitted by RFC 9110/7231) was never resolved against the original request URI and the redirect failed with MalformedURLException: no protocol.

Fix

Resolve the Location against the original request URI per RFC 3986 (URI.create(url).resolve(location)) in both redirect branches before constructing the redirected request. Absolute Locations pass through unchanged; a malformed base/location falls back to the raw value (prior behavior). Only VertxPostBuilder.post() follows redirects (the GET/SSE paths are single-shot by design), so the fix is scoped to those two branches, and no existing redirect-target validation is added or weakened.

Tests

Added synchronousPostFollowsRelativeRedirectLocation (MockServer, single origin): a 302 with Location: /collect is now resolved against the base and followed through to the target. The inherited absolute-Location test confirms absolute Locations still work unchanged. Reverting the resolve step reproduces the original MalformedURLException: no protocol: /collect. mvn -pl extras/http-client-vertx -am test passes (45 tests, 0 failures).

…e request URI

The opt-in redirect follower in VertxA2AHttpClient passed the raw Location
header value straight to WebClient.getAbs()/postAbs(). RFC 9110 (10.2.2) and
RFC 7231 permit a relative Location such as /collect, so a relative value was
handed to an absolute-URI request and failed with MalformedURLException instead
of being followed.

Resolve the Location against the original request URI using RFC 3986 (5)
reference resolution (URI.create(url).resolve(location)) before building the
redirected request. Absolute Location values are returned unchanged, so existing
behavior is preserved; a malformed base or location falls back to the raw value.
No redirect-target validation is added or weakened.

Adds a Vert.x redirect test that serves a relative Location from a single origin
and asserts it is resolved and followed; the inherited absolute-Location tests
continue to pass.

Fixes a2aproject#1142.

Signed-off-by: AlgoVoi <chopmob@gmail.com>
* @param location the raw {@code Location} header value
* @return the absolute redirect target
*/
private static String resolveRedirectLocation(String requestUri, String location) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be package protected so we can add a bunch of unit tests to validate the expected behaviour instead of 'just' a single 'integration' test with mocks

…2aproject#1162)

Make resolveRedirectLocation package-private so RFC 3986 reference
resolution can be unit-tested without a mock server, per review. Add a
focused test class covering absolute-path, relative-path, dot-segment,
query, protocol-relative, already-absolute, and malformed base/location
(raw fallback) cases. The existing mock-server integration test is kept.

Signed-off-by: AlgoVoi <chopmob@gmail.com>

This branch has not been deployed

No deployments
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.

[Bug]: Vert.x opt-in redirects do not support relative Location values.

2 participants