Truly independent web browser
LibWeb: Mark popstate and hashchange events as trusted
Andreas Kling6f7133ac674d
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 547dd1bb2da..d2f9d067a02 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -7823,6 +7823,7 @@ void Document::update_for_history_step_application(NonnullRefPtr<HTML::SessionHiold_url.serialize(),entry->url().serialize(),HighResolutionTime::current_high_resolution_time(relevant_global_object));+ hashchange_event->set_is_trusted(true);HTML::queue_global_task(HTML::Task::Source::DOMManipulation, relevant_global_object, GC::create_function(GC::Heap::the(), [hashchange_event, &window]() {window.dispatch_event(hashchange_event);}));diff --git a/Libraries/LibWeb/HTML/PopStateEvent.cpp b/Libraries/LibWeb/HTML/PopStateEvent.cppindex e962fa23a61..dcf545165f7 100644--- a/Libraries/LibWeb/HTML/PopStateEvent.cpp+++ b/Libraries/LibWeb/HTML/PopStateEvent.cpp@@ -28,7 +28,9 @@ GC::Ref<PopStateEvent> PopStateEvent::create(Utf16FlyString const& event_name, PGC::Ref<PopStateEvent> PopStateEvent::create(FlyString const& event_name, JS::Value state, HighResolutionTime::DOMHighResTimeStamp time_stamp){- return GC::Heap::the().allocate<PopStateEvent>(event_name, state, time_stamp);+ auto event = GC::Heap::the().allocate<PopStateEvent>(event_name, state, time_stamp);+ event->set_is_trusted(true);+ return event;}PopStateEvent::PopStateEvent(FlyString const& event_name, PopStateEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)diff --git a/Tests/LibWeb/Text/expected/HTML/PopStateEvent-constructor-is-untrusted.txt b/Tests/LibWeb/Text/expected/HTML/PopStateEvent-constructor-is-untrusted.txtnew file mode 100644index 00000000000..5a8ed6fb302--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/PopStateEvent-constructor-is-untrusted.txt@@ -0,0 +1,2 @@+new PopStateEvent("popstate").isTrusted is false+new PopStateEvent("popstate", { state: 1 }).isTrusted is falsediff --git a/Tests/LibWeb/Text/input/HTML/PopStateEvent-constructor-is-untrusted.html b/Tests/LibWeb/Text/input/HTML/PopStateEvent-constructor-is-untrusted.htmlnew file mode 100644index 00000000000..28116df953e--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/PopStateEvent-constructor-is-untrusted.html@@ -0,0 +1,10 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ test(() => {+ println(`new PopStateEvent("popstate").isTrusted is ${new PopStateEvent("popstate").isTrusted}`);+ println(+ `new PopStateEvent("popstate", { state: 1 }).isTrusted is ${new PopStateEvent("popstate", { state: 1 }).isTrusted}`+ );+ });+</script>