Std.Http: query values containing `=` are rejected (`?a=b=c`, base64 padding)
Prerequisites
- [x] Check that your issue is not already filed. (Related, but different: #15246, #14934.)
- [x] Reduce the issue to a minimal, self-contained, reproducible test case.
- [ ] Test your test case against the latest nightly release. Not run on nightly: tested on v4.35.0, and
parseQueryandisQueryDataCharare unchanged onmasterat 627881d.
Description
Std.Http.RequestTarget.parse? and Std.Http.URI.parse? fail on any query whose value contains =. Examples:
?a=b=c;- base64 padding, as in
?token=YWJjZA==; - a redirect target with its own query, as in
?next=/x?y=1.
RFC 3986 allows = anywhere in a query: it is a sub-delim inside pchar. Form-urlencoded parsing splits each pair at the first =.
parseQuery in src/Std/Http/Data/URI/Parser.lean looks like it means to allow this:
- It splits each pair on
=. - It joins the rest back together with
String.intercalate "=" value. - It checks the joined value with
URI.EncodedQueryParam.fromString?.
EncodedQueryParam is EncodedQueryString isQueryDataChar, and isQueryDataChar in src/Std/Http/Internal/Char.lean excludes =. So the check rejects the value, the fold returns none, and the whole target fails as "invalid query string".
Percent-encoding the = (?a=b%3Dc) works. But clients, browsers and proxies are not required to encode it, so these requests fail to parse.
Steps to Reproduce
import Std.Http
open Std.Http
#eval (RequestTarget.parse? "/p?a=b").isSome -- true
#eval (RequestTarget.parse? "/p?a=b%3Dc").isSome -- true
#eval (RequestTarget.parse? "/p?a=b=c").isSome -- false
#eval (RequestTarget.parse? "/p?token=YWJjZA==").isSome -- false
#eval (RequestTarget.parse? "/p?next=/x?y=1").isSome -- false
#eval (URI.parse? "http://example.com/p?a=b=c").isSome -- false
Expected behavior: all six print true, and the value of a in ?a=b=c is b=c.
Actual behavior: the last four print false.
Versions
"4.35.0", on Ubuntu 24.04.5 LTS (WSL2).
Additional Information
A fix needs a value check that accepts =. A key still cannot contain an unencoded =. One way is a separate predicate for values; another is to percent-encode = in the value before storing it. I don't know which fits the design of URI.Query best, so I'm opening an issue rather than a PR.
This was found and reduced with AI assistance (Claude Code). The reproduction above was run exactly as shown.
Some additions, from a check of Std.Http on 4.37.0-nightly-2026-10-20 (src/Std/Http/Data/URI/Parser.lean is unchanged on master since 2026-07-23):
- The server rejects these requests: fed to
Std.Http.Protocol.H1.Machine({ config := {} }, thenfeedandstep),GET /a?token=YWJj== HTTP/1.1andGET /login?next=/home?tab=1 HTTP/1.1(withHost: a) get400 Bad Request, whileGET /a?b=c HTTP/1.1is read. tests/elab/async_http_uri.leancurrently expects the rejection, so a fix will need to change that expectation:-- A pair containing more than one unencoded `=` must be rejected because the -- three-element split falls into the error branch. #eval parseCheckFail "/path?key=a=b"- Tested patch for the second option above (keeping the types), in
parseQuery:
Thenlet value ← URI.EncodedQueryParam.fromString? (String.intercalate "%3D" value)?a=b=cgives the valueb%3Dc(decodedb=c),?token=YWJj==givesYWJj%3D%3D(decodedYWJj==), and?next=/x?y=1gives/x?y%3D1(decoded/x?y=1);key=a=breads the same askey=a%3Db, which the test file already accepts. With this change thetests/elab/async_http_*.leanfiles pass except for the expectation above. One difference from the first option: the stored value is the re-encoded form, so serializing the query gives%3Dwhere the request had=.
Found while proving, for a patched copy of Std.Http, that the URI and Host parsers accept every valid request-target and Host value (https://github.com/eumemic/stdhttp-verify, FINDINGS.md §9; the proofs there are about the parser with this patch).
Disclosure: the testing and patch were done with AI assistance (Claude).
Thanks for checking the H1 server path and finding the existing rejection test. Your results make the compatibility trade-off clear: keep the types, accept the value, and serialize the extra = as %3D.
I haven't independently rerun your patch yet. If you plan to submit it, please link the PR here so I can avoid duplicating the work. I'll defer to the maintainers on the representation choice, and your note about updating async_http_uri.lean is particularly helpful.