Skip to content

The agent that grows with you

feat(plugins): desktop surface lint refuses reaching the preview webview

Teknium6e1f1dec1b40
diff --git a/hermes_cli/plugin_validate_desktop.py b/hermes_cli/plugin_validate_desktop.py
index 4fd3911e377..cd1c18677bf 100644
--- a/hermes_cli/plugin_validate_desktop.py
+++ b/hermes_cli/plugin_validate_desktop.py
@@ -38,6 +38,11 @@ _FORBIDDEN: tuple[tuple[str, re.Pattern[str]], ...] = (
r"\[data-(?:slot|tour|sidebar|testid)\b")),
("app DOM reach",
re.compile(r"\.observe\(\s*document\.body\s*,\s*\{[^}]*\b(?:childList|subtree)\b")),
+ # The preview Browser can hold pages the user is signed in to. Script reaches it only through
+ # ``ctx.preview.executeJavaScript``: a declared capability plus the user's per-origin consent.
+ # Grabbing the app's ``<webview>`` (or minting one on the preview partition) skips both.
+ ("preview guest reach",
+ re.compile(r"\b(?:querySelector(?:All)?|closest|getElementsByTagName|createElement)\(\s*[`'\"]webview\b")),
)
# String literals are matched first and kept, so a ``/*`` or ``//`` INSIDE a string (a glob such as
diff --git a/tests/hermes_cli/test_plugin_validate.py b/tests/hermes_cli/test_plugin_validate.py
index 7ab96bf8b9d..5d6f90819c6 100644
--- a/tests/hermes_cli/test_plugin_validate.py
+++ b/tests/hermes_cli/test_plugin_validate.py
@@ -330,6 +330,22 @@ class TestDesktopSurface:
"app DOM reach (desktop/plugin.js:3)",
]
+ def test_preview_guest_reach_fails_and_the_sdk_door_stays_clean(self, tmp_path):
+ """Grabbing or minting a ``<webview>`` to script the preview page skips the declared
+ capability and the user's per-origin consent behind ``ctx.preview``; the SDK door is clean."""
+ d = self._desktop_plugin(tmp_path, (
+ "const title = await ctx.preview.executeJavaScript('document.title')\n"
+ "document.querySelector('webview').executeJavaScript('document.cookie')\n"
+ "const [guest] = document.getElementsByTagName(\"webview\")\n"
+ "const own = document.createElement('webview')\n"
+ "const label = 'webview'\n"
+ ))
+ assert desktop_surface_hits(d) == [
+ "preview guest reach (desktop/plugin.js:2)",
+ "preview guest reach (desktop/plugin.js:3)",
+ "preview guest reach (desktop/plugin.js:4)",
+ ]
+
def test_chunk_import_fails_and_prototype_writes_are_left_to_review(self, tmp_path):
d = self._desktop_plugin(tmp_path, (
"const raw = Storage.prototype.setItem\n"