Skip to content

Commit

Permalink
LibWeb: Fix crash in Headers::get with non-ASCII characters
Browse files Browse the repository at this point in the history
headers list is ISO-8859-1 encoded using `Infra::isomorphic_encode`,
so we should use decode them using `Infra::isomorphic_decode`
before return.
  • Loading branch information
F3n67u committed Dec 7, 2024
1 parent 46b9518 commit 0b18dd5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Libraries/LibWeb/Fetch/Headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <LibWeb/Bindings/HeadersPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Fetch/Headers.h>
#include <LibWeb/Infra/Strings.h>

namespace Web::Fetch {

Expand Down Expand Up @@ -106,7 +107,7 @@ WebIDL::ExceptionOr<Optional<String>> Headers::get(String const& name_string)

// 2. Return the result of getting name from this’s header list.
auto byte_buffer = m_header_list->get(name);
return byte_buffer.has_value() ? MUST(String::from_utf8(*byte_buffer)) : Optional<String> {};
return byte_buffer.has_value() ? Infra::isomorphic_decode(*byte_buffer) : Optional<String> {};
}

// https://fetch.spec.whatwg.org/#dom-headers-getsetcookie
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
before-æøå-after
before-ß-after
13 changes: 13 additions & 0 deletions Tests/LibWeb/Text/input/Fetch/fetch-headers-get-nonascii.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
// This test ensures that the Headers get() methods can handle non-ASCII latin1 characters: code points U+0080-U+00FF.
test(() => {
const headers = new Headers({
"Accept": "before-æøå-after",
"X-Test": "before-ß-after"
});
println(headers.get("Accept"));
println(headers.get("X-Test"));
});
</script>

0 comments on commit 0b18dd5

Please sign in to comment.