Make localStorage and sessionStorage throw on opaque origins (#44002)

Testing: covered by WPT test.
Fixes #43999

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi
2026-04-07 22:41:10 +02:00
committed by GitHub
parent 9334d3094b
commit ac4df79bd6
5 changed files with 61 additions and 15 deletions

View File

@@ -1856,7 +1856,9 @@ impl ScriptThread {
key,
old_value,
new_value,
) => self.handle_storage_event(pipeline_id, storage, url, key, old_value, new_value),
) => {
self.handle_storage_event(pipeline_id, storage, url, key, old_value, new_value, cx)
},
ScriptThreadMessage::ReportCSSError(pipeline_id, filename, line, column, msg) => {
self.handle_css_error_reporting(pipeline_id, filename, line, column, msg)
},
@@ -3280,6 +3282,7 @@ impl ScriptThread {
}
/// Notify a window of a storage event
#[allow(clippy::too_many_arguments)]
fn handle_storage_event(
&self,
pipeline_id: PipelineId,
@@ -3288,14 +3291,18 @@ impl ScriptThread {
key: Option<String>,
old_value: Option<String>,
new_value: Option<String>,
cx: &mut js::context::JSContext,
) {
let Some(window) = self.documents.borrow().find_window(pipeline_id) else {
return warn!("Storage event sent to closed pipeline {pipeline_id}.");
};
let storage = match storage_type {
WebStorageType::Local => window.LocalStorage(),
WebStorageType::Session => window.SessionStorage(),
WebStorageType::Local => window.GetLocalStorage(cx),
WebStorageType::Session => window.GetSessionStorage(cx),
};
let Ok(storage) = storage else {
return;
};
storage.queue_storage_event(url, key, old_value, new_value);