Skip to content

escape quoted-string parameter values in ForwardedRequest - #1543

Merged
ok2c merged 2 commits into
apache:masterfrom
rootvector2:forwarded-host-quoting
Nov 29, 2026
Merged

ok2c merged 2 commits into
apache:masterfrom
rootvector2:forwarded-host-quoting

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

ForwardedRequest builds the host parameter by concatenating host=" + authority.getHostName() + ", with no quoted-pair escaping. The host name is whatever the client put in the Host header, and Host.parse happily accepts a ", so Host: somehost",for=127.0.0.1;host="otherhost comes back out as host="somehost",for=127.0.0.1;host="otherhost";proto=HTTP. That is a well formed two element Forwarded list whose second element is entirely client controlled, so a downstream node that takes for= from the closest element is handed an attacker chosen client address and any IP based trust decision on that field is void. Found while reading through the proxy interceptors in http.protocol.

Escape DQUOTE and \ per RFC 9110 section 5.6.4 at the three points where a quoted parameter is emitted. by and for share the helper because their values come from InetSocketAddress.getHostString(), which returns the host name the socket was created with and on a forwarded connection that name is also client supplied. The escaping belongs in the interceptor that assembles the field value, so no caller has to pre-sanitize the authority.

valueBuilder.append(";");
}
valueBuilder.append("host=\"").append(authority.getHostName()).append("\"");
valueBuilder.append("host=");

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.

@rootvector2 Can make it a bit more consistent with the rest of the code base? Could you please use BasicHeaderValueFormatter#formatNameValuePair method provided by BasicHeaderValueFormatter#INSTANCE to format by, for and host name/value pairs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. All three now go through BasicHeaderValueFormatter.INSTANCE.formatNameValuePair, with valueBuilder switched to CharArrayBuffer.

host passes quote=true so it stays unconditionally quoted as before. by and for pass quote=false, but the formatter quotes them anyway because of the : before the port, so the Inet6Address branch became dead and I dropped it. Side effect: IPv4 by/for go from by=1.2.3.4:5 to by="1.2.3.4:5", which is the correct form since : is not a tchar. Updated the two tests that asserted the unquoted value; full verify is green.

@ok2c ok2c added this to the 5.5.1 milestone Nov 29, 2026
@ok2c
ok2c merged commit cb7ad98 into apache:master Nov 29, 2026
12 checks passed
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.

2 participants