LibWeb: Use document's global object in is_base_allowed_for_document

Previously we were using the document's window - this was both contrary
to spec and causing crashes when the document did not have a window (for
instance the `temp_document` in `HTMLParser::parse_html_fragment`.

This means we no longer crash when navigating between pages on
https://rocketlabcorp.com
This commit is contained in:
Callum Law 2025-08-16 22:01:27 +12:00 committed by Andreas Kling
commit 71b039a721
Notes: github-actions[bot] 2025-08-16 12:20:01 +00:00
2 changed files with 8 additions and 2 deletions

View file

@ -625,8 +625,7 @@ JS::ThrowCompletionOr<void> ensure_csp_does_not_block_wasm_byte_compilation(JS::
Directives::Directive::Result is_base_allowed_for_document(JS::Realm& realm, URL::URL const& base, GC::Ref<DOM::Document const> document) Directives::Directive::Result is_base_allowed_for_document(JS::Realm& realm, URL::URL const& base, GC::Ref<DOM::Document const> document)
{ {
// 1. For each policy of documents global objects csp list: // 1. For each policy of documents global objects csp list:
VERIFY(document->window()); auto csp_list = PolicyList::from_object(document->realm().global_object());
auto csp_list = PolicyList::from_object(*document->window());
VERIFY(csp_list); VERIFY(csp_list);
for (auto const policy : csp_list->policies()) { for (auto const policy : csp_list->policies()) {
// 1. Let source list be null. // 1. Let source list be null.

View file

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html id="html">
<head></head>
<script>
document.head.innerHTML = `<base href="https://example.com">`;
</script>
</html>