Repository navigation
escape quoted-string parameter values in ForwardedRequest - #1543
Conversation
| valueBuilder.append(";"); | ||
| } | ||
| valueBuilder.append("host=\"").append(authority.getHostName()).append("\""); | ||
| valueBuilder.append("host="); |
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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.
ForwardedRequestbuilds thehostparameter by concatenatinghost="+authority.getHostName()+", with noquoted-pairescaping. The host name is whatever the client put in theHostheader, andHost.parsehappily accepts a", soHost: somehost",for=127.0.0.1;host="otherhostcomes back out ashost="somehost",for=127.0.0.1;host="otherhost";proto=HTTP. That is a well formed two elementForwardedlist whose second element is entirely client controlled, so a downstream node that takesfor=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 inhttp.protocol.Escape
DQUOTEand\per RFC 9110 section 5.6.4 at the three points where a quoted parameter is emitted.byandforshare the helper because their values come fromInetSocketAddress.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.