Skip to content

Truly independent web browser

LibWeb: Expose speech recognition only in secure contexts

Shannon Boothbf14e0a9e708
diff --git a/Libraries/LibWeb/Speech/SpeechRecognition.idl b/Libraries/LibWeb/Speech/SpeechRecognition.idl
index 1c2573fb54a..6ad2e396c7f 100644
--- a/Libraries/LibWeb/Speech/SpeechRecognition.idl
+++ b/Libraries/LibWeb/Speech/SpeechRecognition.idl
@@ -1,5 +1,5 @@
// https://wicg.github.io/speech-api/#speechrecognition
-[Exposed=Window, ImplementedIn=Rust]
+[SecureContext, Exposed=Window, ImplementedIn=Rust]
interface SpeechRecognition : EventTarget {
constructor();
diff --git a/Libraries/LibWeb/Speech/SpeechRecognitionAlternative.idl b/Libraries/LibWeb/Speech/SpeechRecognitionAlternative.idl
index 22b6bf11f9a..b8d2fc564ac 100644
--- a/Libraries/LibWeb/Speech/SpeechRecognitionAlternative.idl
+++ b/Libraries/LibWeb/Speech/SpeechRecognitionAlternative.idl
@@ -1,5 +1,5 @@
// https://wicg.github.io/speech-api/#speechrecognitionalternative
-[Exposed=Window, ImplementedIn=Rust]
+[SecureContext, Exposed=Window, ImplementedIn=Rust]
interface SpeechRecognitionAlternative {
readonly attribute DOMString transcript;
readonly attribute float confidence;
diff --git a/Libraries/LibWeb/Speech/SpeechRecognitionEvent.idl b/Libraries/LibWeb/Speech/SpeechRecognitionEvent.idl
index a9624931ac9..66be62828f2 100644
--- a/Libraries/LibWeb/Speech/SpeechRecognitionEvent.idl
+++ b/Libraries/LibWeb/Speech/SpeechRecognitionEvent.idl
@@ -1,5 +1,5 @@
// https://wicg.github.io/speech-api/#speechrecognitionevent
-[Exposed=Window, ImplementedIn=Rust]
+[SecureContext, Exposed=Window, ImplementedIn=Rust]
interface SpeechRecognitionEvent : Event {
constructor(DOMString type, SpeechRecognitionEventInit eventInitDict);
readonly attribute unsigned long resultIndex;
diff --git a/Libraries/LibWeb/Speech/SpeechRecognitionPhrase.idl b/Libraries/LibWeb/Speech/SpeechRecognitionPhrase.idl
index c8fbabaf360..4d990c17052 100644
--- a/Libraries/LibWeb/Speech/SpeechRecognitionPhrase.idl
+++ b/Libraries/LibWeb/Speech/SpeechRecognitionPhrase.idl
@@ -1,5 +1,5 @@
// https://wicg.github.io/speech-api/#speechrecognitionphrase
-[Exposed=Window, ImplementedIn=Rust]
+[SecureContext, Exposed=Window, ImplementedIn=Rust]
interface SpeechRecognitionPhrase {
constructor(DOMString phrase, optional float boost = 1.0);
readonly attribute DOMString phrase;
diff --git a/Libraries/LibWeb/Speech/SpeechRecognitionResult.idl b/Libraries/LibWeb/Speech/SpeechRecognitionResult.idl
index 18fd8f08d11..f33f6f5897a 100644
--- a/Libraries/LibWeb/Speech/SpeechRecognitionResult.idl
+++ b/Libraries/LibWeb/Speech/SpeechRecognitionResult.idl
@@ -1,5 +1,5 @@
// https://wicg.github.io/speech-api/#speechrecognitionresult
-[Exposed=Window, ImplementedIn=Rust]
+[SecureContext, Exposed=Window, ImplementedIn=Rust]
interface SpeechRecognitionResult {
readonly attribute unsigned long length;
getter SpeechRecognitionAlternative? item(unsigned long index);
diff --git a/Libraries/LibWeb/Speech/SpeechRecognitionResultList.idl b/Libraries/LibWeb/Speech/SpeechRecognitionResultList.idl
index be27ca0b20b..18dd187cf1e 100644
--- a/Libraries/LibWeb/Speech/SpeechRecognitionResultList.idl
+++ b/Libraries/LibWeb/Speech/SpeechRecognitionResultList.idl
@@ -1,5 +1,5 @@
// https://wicg.github.io/speech-api/#speechrecognitionresultlist
-[Exposed=Window, ImplementedIn=Rust]
+[SecureContext, Exposed=Window, ImplementedIn=Rust]
interface SpeechRecognitionResultList {
readonly attribute unsigned long length;
getter SpeechRecognitionResult? item(unsigned long index);
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 0a51e338b6e..858fa19e846 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -1331,6 +1331,7 @@ Text/input/wpt-import/geolocation/non-secure-contexts.http.html
Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.html
; Upstream serves it from a page that is not potentially trustworthy, where its data: frame's blob: worker is not mixed content.
Text/input/wpt-import/webmessaging/broadcastchannel/opaque-origin.html
+Text/input/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.html
[Skipped]
; Need position-visibility: no-overflow to hide a target that overflows after scrolling
diff --git a/Tests/LibWeb/Text/expected/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.txt b/Tests/LibWeb/Text/expected/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.txt
new file mode 100644
index 00000000000..0c86bbcf2dc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.txt
@@ -0,0 +1,13 @@
+Harness status: OK
+
+Found 8 tests
+
+8 Pass
+Pass This page is not a secure context
+Pass SpeechRecognition is not exposed
+Pass SpeechRecognitionErrorEvent is not exposed
+Pass SpeechRecognitionAlternative is not exposed
+Pass SpeechRecognitionResult is not exposed
+Pass SpeechRecognitionResultList is not exposed
+Pass SpeechRecognitionEvent is not exposed
+Pass SpeechRecognitionPhrase is not exposed
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.html b/Tests/LibWeb/Text/input/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.html
new file mode 100644
index 00000000000..13759350d2f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Speech recognition is not exposed in a non-secure context</title>
+<script src=../resources/testharness.js></script>
+<script src=../resources/testharnessreport.js></script>
+<script>
+test(() => {
+ assert_false(self.isSecureContext);
+}, "This page is not a secure context");
+
+for (const name of ["SpeechRecognition", "SpeechRecognitionErrorEvent", "SpeechRecognitionAlternative", "SpeechRecognitionResult", "SpeechRecognitionResultList", "SpeechRecognitionEvent", "SpeechRecognitionPhrase"]) {
+ test(() => {
+ assert_false(name in self);
+ }, `${name} is not exposed`);
+}
+</script>