]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[uri] Retain original encodings for path, query, and fragment fields 516/head
authorMichael Brown <mcb30@ipxe.org>
Thu, 11 Nov 2021 23:31:23 +0000 (23:31 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 12 Nov 2021 09:58:29 +0000 (09:58 +0000)
commit1844aacc837bf81cb1959fa65f2e52dcc70a0cae
tree8ad8156c38473e608269251518c125a8cb0bda5d
parent85eb961bf9afd61385430f8837485ba69cc0cc11
[uri] Retain original encodings for path, query, and fragment fields

iPXE decodes any percent-encoded characters during the URI parsing
stage, thereby allowing protocol implementations to consume the raw
field values directly without further decoding.

When reconstructing a URI string for use in an HTTP request line, the
percent-encoding is currently reapplied in a reversible way: we
guarantee that our reconstructed URI string could be decoded to give
the same raw field values.

This technically violates RFC3986, which states that "URIs that differ
in the replacement of a reserved character with its corresponding
percent-encoded octet are not equivalent".  Experiments show that
several HTTP server applications will attach meaning to the choice of
whether or not a particular character was percent-encoded, even when
the percent-encoding is unnecessary from the perspective of parsing
the URI into its component fields.

Fix by storing the originally encoded substrings for the path, query,
and fragment fields and using these original encoded versions when
reconstructing a URI string.  The path field is also stored as a
decoded string, for use by protocols such as TFTP that communicate
using raw strings rather than URI-encoded strings.  All other fields
(such as the username and password) continue to be stored only in
their decoded versions since nothing ever needs to know the originally
encoded versions of these fields.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/uri.c
src/include/ipxe/uri.h
src/net/tcp/httpcore.c
src/tests/uri_test.c
src/usr/imgmgmt.c