LibWeb: Avoid UAF when encoding a fetch request body via URLSearchParams

This commit is contained in:
Timothy Flynn 2024-04-03 15:54:22 -04:00 committed by Tim Flynn
parent d91d6ee205
commit 69b5d7c0e6
Notes: sideshowbarker 2024-07-17 08:34:29 +09:00
3 changed files with 19 additions and 2 deletions

View file

@ -0,0 +1 @@
username=buggie&password=hunter2

View file

@ -0,0 +1,16 @@
<script src="include.js"></script>
<script type="text/javascript">
asyncTest(async done => {
const body = new URLSearchParams();
body.append("username", "buggie");
body.append("password", "hunter2");
const request = new Request("fetch-url-search-params.html", {
method: "POST",
body: body,
});
println(await request.text());
done();
});
</script>

View file

@ -105,8 +105,8 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
},
[&](JS::Handle<DOMURL::URLSearchParams> const& url_search_params) -> WebIDL::ExceptionOr<void> {
// Set source to the result of running the application/x-www-form-urlencoded serializer with objects list.
auto search_params_bytes = TRY(url_search_params->to_string()).bytes();
source = TRY_OR_THROW_OOM(vm, ByteBuffer::copy(search_params_bytes));
auto search_params_string = TRY(url_search_params->to_string());
source = TRY_OR_THROW_OOM(vm, ByteBuffer::copy(search_params_string.bytes()));
// Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
type = TRY_OR_THROW_OOM(vm, ByteBuffer::copy("application/x-www-form-urlencoded;charset=UTF-8"sv.bytes()));
return {};