fix: close keyframe bypasses on protected controls without policing skin layout

Hold @keyframes to the same hide/yeet checks as regular declarations,
including escaped and namespaced animation names. Loosen decorative
host-chrome layout locks so open skins can restyle layout freely.
Listen for the recovery shortcut in the capture phase, move the
load-failure banner into the host-owned layer, and fix recovery
aria-labels.
This commit is contained in:
OddTurtleHead committed 2026-11-15 01:09:42 +08:00
1 parent a84f66b47d
commit a4ae4de82f
9 files changed
+286 -57

No files matched your search

+6 -3
View File
@@ -162,13 +162,16 @@ function openLibrary() {
}
function onKeydown(event: KeyboardEvent) {
if (event.defaultPrevented || event.repeat || !thirdPartyAllowed.value) return;
if (event.repeat || !thirdPartyAllowed.value) return;
// The recovery chord must survive a capture-phase preventDefault() from a
// skin or plugin, so it runs before the defaultPrevented check below.
if (isRecoveryShortcut(event)) {
event.preventDefault();
shortcutOpen.value = true;
void nextTick(() => recoveryPopover.value?.querySelector("button")?.focus());
return;
}
if (event.defaultPrevented) return;
if (event.key === "Escape" && shortcutOpen.value) shortcutOpen.value = false;
}
@@ -184,13 +187,13 @@ onMounted(() => {
refreshLauncherReachability();
reachabilityTimer = setInterval(refreshLauncherReachability, 1000);
window.addEventListener("resize", refreshLauncherReachability);
window.addEventListener("keydown", onKeydown);
window.addEventListener("keydown", onKeydown, true);
void nextTick(syncPopover);
});
onBeforeUnmount(() => {
if (reachabilityTimer) clearInterval(reachabilityTimer);
window.removeEventListener("resize", refreshLauncherReachability);
window.removeEventListener("keydown", onKeydown);
window.removeEventListener("keydown", onKeydown, true);
layer?.dispose();
});
</script>
+14 -6
View File
@@ -1,5 +1,5 @@
<template>
<Teleport to="body">
<Teleport v-if="layer" :to="layer.container">
<section v-if="error" class="skin-load-recovery" data-ws-part="app.skin-load-recovery" role="alert">
<p>{{ labels.skinLoadError(error.skinId) }}</p>
<button type="button" @click="$emit('use-built-in')">{{ labels.skinUseBuiltIn }}</button>
@@ -8,9 +8,10 @@
</template>
<script setup lang="ts">
import { computed } from "vue";
import { computed, onBeforeUnmount } from "vue";
import type { Language } from "../i18n/web-client.js";
import { resolveSkinLayoutLanguage, skinLayoutLabels } from "../i18n/skin-layout.js";
import { createHostOwnedLayer, type HostOwnedLayer } from "../services/host-owned-layer.js";
defineEmits<{ "use-built-in": [] }>();
@@ -19,9 +20,11 @@ const props = defineProps<{
language: Language;
}>();
const labels = computed(() => skinLayoutLabels[resolveSkinLayoutLanguage(props.language)]);
</script>
<style scoped>
// The banner is trusted host UI: render it in a closed shadow root so compiled
// skin CSS cannot restyle it (or hide it) from the document. The layer's fixed
// wrapper is pointer-transparent, so the banner re-enables pointer events.
const SKIN_LOAD_LAYER_CSS = `
.skin-load-recovery {
position: fixed;
z-index: 2147482500;
@@ -40,13 +43,18 @@ const labels = computed(() => skinLayoutLabels[resolveSkinLayoutLanguage(props.l
background: #fffbeb;
box-shadow: 0 8px 28px #0f172a33;
font: 14px/1.45 ui-sans-serif, system-ui, sans-serif;
pointer-events: auto;
}
.skin-load-recovery p { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.skin-load-recovery button { flex: 0 0 auto; min-height: 44px; max-width: 100%; padding: 7px 10px; border: 1px solid #b45309; border-radius: 8px; color: #78350f; background: #fff; cursor: pointer; white-space: normal; }
.skin-load-recovery button:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 2px; }
@media (max-width: 520px) {
.skin-load-recovery { align-items: stretch; flex-direction: column; gap: 7px; }
.skin-load-recovery button { width: 100%; }
}
</style>
`;
const layer: HostOwnedLayer | null = createHostOwnedLayer("skin-load", SKIN_LOAD_LAYER_CSS);
onBeforeUnmount(() => layer?.dispose());
</script>
+5 -5
View File
@@ -4,7 +4,7 @@ import type { SiteLanguage } from "../../../src/site-copy.js";
const en = {
hint: "Audio controls remain available in the toolbar and voice workspace.",
library: "Application library",
recovery: "Restore application library",
recovery: "Restore built-in skin",
useBuiltIn: "Use built-in skin",
shortcut: "Restore the built-in skin (Ctrl+Alt+Shift+R, or ⌘+⌥+⇧+R on macOS)",
};
@@ -13,28 +13,28 @@ export const hostChromeCopy: Record<SiteLanguage, typeof en> = {
zh: {
hint: "音频控制始终保留在工具栏和语音工作区中。",
library: "应用库",
recovery: "恢复应用库",
recovery: "恢复内置皮肤",
useBuiltIn: "使用内置皮肤",
shortcut: "恢复内置皮肤(Ctrl+Alt+Shift+R,macOS 为 ⌘+⌥+⇧+R)",
},
de: {
hint: "Audiosteuerung bleibt in der Werkzeugleiste und im Sprachbereich verfügbar.",
library: "Anwendungsbibliothek",
recovery: "Anwendungsbibliothek wiederherstellen",
recovery: "Integrierten Skin wiederherstellen",
useBuiltIn: "Integrierten Skin verwenden",
shortcut: "Integrierten Skin wiederherstellen (Strg+Alt+Umschalt+R, unter macOS ⌘+⌥+⇧+R)",
},
ru: {
hint: "Управление звуком остаётся доступным на панели инструментов и в голосовой области.",
library: "Библиотека приложений",
recovery: "Восстановить библиотеку приложений",
recovery: "Восстановить встроенную тему",
useBuiltIn: "Использовать встроенную тему",
shortcut: "Восстановить встроенную тему (Ctrl+Alt+Shift+R, в macOS ⌘+⌥+⇧+R)",
},
ja: {
hint: "音声コントロールはツールバーと音声ワークスペースで常に利用できます。",
library: "アプリライブラリ",
recovery: "アプリライブラリを復元",
recovery: "組み込みスキンを復元",
useBuiltIn: "組み込みスキンを使用",
shortcut: "組み込みスキンを復元(Ctrl+Alt+Shift+R、macOS は ⌘+⌥+⇧+R)",
},
+1 -1
View File
@@ -17,7 +17,7 @@
* without the Popover API still shows the UI above ordinary content.
*/
export type HostOwnedLayerName = "recovery" | "authorization";
export type HostOwnedLayerName = "recovery" | "authorization" | "skin-load";
/**
* The CSS 32-bit maximum stacking value. A compiled skin may legitimately use
+2
View File
@@ -26,6 +26,8 @@
<div id="overlay" data-ws-part="host.plugins.overlay">Application library</div>
<button type="button" id="launcher" data-ws-part="host.plugins.launcher">Plugins</button>
</div>
<!-- Decorative host chrome lives outside the skin root in the real client. -->
<div id="watermark" data-ws-part="host.watermark" aria-hidden="true">Watermark</div>
<div id="app"></div>
<div id="auth-app"></div>
<pre id="result" style="position:relative;z-index:5;background:#fff">pending</pre>
+23 -1
View File
@@ -42,15 +42,26 @@ const scenarios = [
name: "pointer-events-none",
css: compileHostile('[data-ws-part="host.plugins.launcher"], [data-ws-part="host.plugins.overlay"] { pointer-events: none !important; }'),
},
{
// Decorative host chrome may legitimately be a fixed, viewport-sized,
// max-stacking decoration. Recovery lives in a closed-shadow top layer and
// must still win the hit test.
name: "decorative-watermark-overlay",
css: compileHostile(`
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(12px); } }
[data-ws-part="host.watermark"] { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 2147483647; background: #123; animation: drift 3s ease-in-out infinite alternate; }
`),
},
];
test("host chrome renders recovery and authorization in a closed-shadow top layer", async () => {
const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin] = await Promise.all([
const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin, recoveryNotice] = await Promise.all([
read("../src/components/HostChrome.vue"),
read("../src/components/InstanceAuthorization.vue"),
read("../src/services/host-owned-layer.ts"),
read("../src/services/host-chrome.ts"),
read("../src/composables/usePublicSkin.ts"),
read("../src/components/SkinLoadRecoveryNotice.vue"),
]);
// Recovery: closed shadow root + manual popover + no skin hook.
@@ -59,6 +70,11 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye
assert.match(hostChrome, /data-ws-recovery-action="built-in"/);
assert.match(hostChrome, /requestBuiltInSkin/);
assert.match(hostChrome, /isThirdPartySkinActive/);
// The shortcut runs in the capture phase so a plugin/skin capture listener
// cannot swallow it with preventDefault().
assert.match(hostChrome, /addEventListener\("keydown", onKeydown, true\)/);
assert.match(hostChrome, /removeEventListener\("keydown", onKeydown, true\)/);
assert.doesNotMatch(hostChrome, /event\.defaultPrevented \|\| event\.repeat/);
assert.doesNotMatch(hostChrome, /data-ws-part="host\.recovery"/);
assert.doesNotMatch(hostChrome, /ws-host-recovery-layer/);
@@ -67,6 +83,12 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye
assert.match(authorization, /showModal\(\)/);
assert.doesNotMatch(authorization, /data-ws-part="host\.permission"/);
// The load-failure banner is trusted UI too: closed shadow layer, stylesheet
// inside the boundary, no document-level scoped stylesheet to override.
assert.match(recoveryNotice, /createHostOwnedLayer\("skin-load"/);
assert.match(recoveryNotice, /data-ws-part="app\.skin-load-recovery"/);
assert.doesNotMatch(recoveryNotice, /<style scoped>/);
// The layer itself: closed shadow root, no data-ws-part, fixed fallback.
assert.match(ownedLayer, /attachShadow\(\{ mode: "closed" \}\)/);
assert.match(ownedLayer, /data-ws-host-layer/);