Skip to content

[Regression in 5.5] Fix double-bracketing of IPv6 literals - #1548

Merged
garydgregory merged 1 commit into
apache:masterfrom
garydgregory:fix-ipv6-double-bracketing
Dec 1, 2026
Merged

garydgregory merged 1 commit into
apache:masterfrom
garydgregory:fix-ipv6-double-bracketing

Conversation

@garydgregory

@garydgregory garydgregory commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

This is a regression in 5.5 since 5.4.4.

Preserve already bracketed IPv6 literals and encoded zone IDs when formatting URI authorities.

Add regression coverage for IPv6 address forms, ports, user info, zone encoding, and non-IPv6 inputs.

The client will send the wrong HTTP Host header which will cause the server to return a 4xx bad request error.

A client-based reproducer can be boiled down to:

new org.apache.hc.client5.http.classic.methods.HttpPost(new java.net.URI("http://[::1]:8080")).getAuthority().toString()

For example:

2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "Host: [[::1]]:59149[\r][\n]"

extracted from this log:

2026-12-01T07:50:17,107 DEBUG [Time-limited test][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager] ep-0000000001 executing exchange ex-0000000001 over http-outgoing-0
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> POST /lde/ HTTP/1.1
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> Accept-Encoding: gzip, deflate, br, lz4-framed, lz4-block, bzip2, pack200, deflate64, x-gzip
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> Host: [[::1]]:59149
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> Content-Length: 244
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> Content-Type: text/xml; charset=UTF-8
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> Connection: keep-alive
2026-12-01T07:50:17,108 DEBUG [Time-limited test][org.apache.hc.client5.http.headers] http-outgoing-0 >> User-Agent: Apache-HttpClient/5.6.5 (Java/17.0.21)
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "POST /lde/ HTTP/1.1[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "Accept-Encoding: gzip, deflate, br, lz4-framed, lz4-block, bzip2, pack200, deflate64, x-gzip[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "Host: [[::1]]:59149[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "Content-Length: 244[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "Content-Type: text/xml; charset=UTF-8[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "Connection: keep-alive[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "User-Agent: Apache-HttpClient/5.6.5 (Java/17.0.21)[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "[\r][\n]"
2026-12-01T07:50:17,109 DEBUG [Time-limited test][org.apache.hc.client5.http.wire] http-outgoing-0 >> "<?xml version="1.0" encoding="UTF-8"?><?com.seagullsw.appinterface.model.ModelIORegistry elementType="function"elementAspect="request"bindingType="AppInterface"syntaxVersion="7.0"?><Request name="com.seagullsw.appinterface.server.admin.Logon"/>"
2026-12-01T07:50:17,111 DEBUG [qtp745089008-55][org.eclipse.jetty.io.IdleTimeout] Setting idle timeout 0 -> 30000 on oeji.SocketChannelEndPoint@959f82[{l=/[0:0:0:0:0:0:0:1]:59149,r=/[0:0:0:0:0:0:0:1]:59150,OPEN,fill=-,flush=-,to=4/30000}{:io=0/0,kio=0,kro=0}]->[<null>]

Here is the failure on the Server side (Jetty):

2026-12-01T07:50:17,154 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] parseNext s=START jn.DirectByteBuffer@51ec6d40[p=0,l=518,c=8192,r=518]={<<<POST /lde/ HTTP/1.1\r\nAcce...e.server.admin.Logon"/>>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}
2026-12-01T07:50:17,155 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] START --> SPACE1(POST)
2026-12-01T07:50:17,157 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] SPACE1 --> URI
2026-12-01T07:50:17,157 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] URI --> HEADER
2026-12-01T07:50:17,162 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] HEADER:FIELD --> IN_VALUE
2026-12-01T07:50:17,162 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] HEADER:IN_VALUE --> FIELD(Accept-Encoding: gzip, deflate, br, lz4-framed, lz4-block, bzip2, pack200, deflate64, x-gzip)
2026-12-01T07:50:17,162 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] parsedHeader(Accept-Encoding: gzip, deflate, br, lz4-framed, lz4-block, bzip2, pack200, deflate64, x-gzip) header=Accept-Encoding, headerString=[Accept-Encoding], valueString=[gzip, deflate, br, lz4-framed, lz4-block, bzip2, pack200, deflate64, x-gzip]
2026-12-01T07:50:17,163 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] HEADER:FIELD --> VALUE
2026-12-01T07:50:17,163 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] HEADER:VALUE --> IN_VALUE
2026-12-01T07:50:17,163 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] HEADER:IN_VALUE --> FIELD(Host: [[::1]]:59149)
2026-12-01T07:50:17,163 WARN  [qtp745089008-56][org.eclipse.jetty.util.HostPort] Bad IPv6 host: [[[::1]]]
2026-12-01T07:50:17,163 DEBUG [qtp745089008-56][org.eclipse.jetty.http.HttpParser] Parse exception: oejh.HttpParser{s=HEADER,0 of -1} for org.eclipse.jetty.server.internal.HttpConnection$RequestHandler@3cc99e0a
org.eclipse.jetty.http.HttpException$RuntimeException: 400: Bad HostPort
	at org.eclipse.jetty.http.HostPortHttpField.<init>(HostPortHttpField.java:41)
	at org.eclipse.jetty.http.HttpParser.parsedHeader(HttpParser.java:1251)
	at org.eclipse.jetty.http.HttpParser.parseFields(HttpParser.java:1444)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1729)
	at org.eclipse.jetty.server.internal.HttpConnection.parseRequestBuffer(HttpConnection.java:613)
	at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:388)
	at org.eclipse.jetty.server.internal.HttpConnection$FillableCallback.succeeded(HttpConnection.java:1789)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:54)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:1009)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1240)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1194)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.IllegalArgumentException: Bad IPv6 host
	at org.eclipse.jetty.util.HostPort.<init>(HostPort.java:110)
	at org.eclipse.jetty.util.HostPort.<init>(HostPort.java:62)
	at org.eclipse.jetty.http.HostPortHttpField.<init>(HostPortHttpField.java:37)
	... 12 more

Preserve already bracketed IPv6 literals and encoded zone IDs when
formatting URI authorities.

Add regression coverage for IPv6 address forms, ports, user info,
zone encoding, and non-IPv6 inputs.
@garydgregory
garydgregory requested review from ok2c and a balanced review from Copilot December 1, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the IPv6 authority-formatting change.

No open issues 🎉

What changed in this PR

Fixes IPv6 authority formatting to prevent double brackets in HTTP Host headers while preserving existing zone-ID encoding.

Changes:

  • Appends already bracketed IPv6 literals unchanged and documents that behavior.
  • Adds regression coverage for IPv6 forms, zone IDs, ports, user info, and non-IPv6 inputs.
File Description
httpcore5/​src/​test/​java/​org/​apache/​hc/​core5/​net/​TestZoneIdSupport.java Tests IPv6 formatting, zone encoding, and unchanged buffers for non-IPv6 inputs.
httpcore5/​src/​test/​java/​org/​apache/​hc/​core5/​net/​TestURIAuthority.java Tests bracketed IPv6 authorities with varied user info and ports.
httpcore5/​src/​main/​java/​org/​apache/​hc/​core5/​net/​ZoneIdSupport.java Preserves already bracketed IPv6 literals and updates the method documentation.

Review effort: Balanced

@garydgregory garydgregory changed the title Fix double-bracketing of IPv6 literals [regression in 5.5] Fix double-bracketing of IPv6 literals Dec 1, 2026
@garydgregory garydgregory changed the title [regression in 5.5] Fix double-bracketing of IPv6 literals [Regression in 5.5] Fix double-bracketing of IPv6 literals Dec 1, 2026

@ok2c ok2c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@garydgregory Looks good to me

@arturobernalg Could you please take a look?

@ok2c
ok2c requested a review from arturobernalg December 1, 2026 18:03
@ok2c ok2c added this to the 5.5.1 milestone Dec 1, 2026

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh........ this restores 5.4.x behavior. LGTM

@garydgregory
garydgregory merged commit ac70faf into apache:master Dec 1, 2026
12 checks passed
@garydgregory
garydgregory deleted the fix-ipv6-double-bracketing branch December 2, 2026 11:26
ok2c pushed a commit that referenced this pull request Dec 2, 2026
Preserve already bracketed IPv6 literals and encoded zone IDs when
formatting URI authorities.

Add regression coverage for IPv6 address forms, ports, user info,
zone encoding, and non-IPv6 inputs.
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.

4 participants