nb5p (Discord #feedback, 10-31): the 模型指纹 page stays blank in the desktop app while `magpie web` (Chromium) shows it. Cause, Linux: magpie frames a plugin page in <iframe sandbox="allow-scripts">, so the service document has an opaque origin. WebKitGTK (2.52.6, magpie's Linux window) then matches nothing to CSP 'self', and the service's policy was 'self' alone for scripts, styles and images: the bundle was never requested. Chromium and macOS WebKit match 'self' there, so web mode and the Mac app worked. The service now names its own validated listener (http://127.0.0.1:<port> or localhost:<port>) and, when proxied, the validated launcher origin, in every fetch directive. Nothing else is allowed: script-src keeps its nonce and no 'unsafe-inline', and object-src/base-uri/form-action are 'none'. Two Windows faults on the same path: - boot.js took the window's http://wails.localhost for a remote web page and showed "upgrade magpie" instead of going to the local service. Every *.localhost, localhost, ::1 and 127.x now count as this computer (the service still checks Host and Origin and its bearer token). - server.ts kept assets inside ui/ with startsWith(resolve(uiDir) + "/"), which never holds for backslash paths, so every asset was a 404 on Windows, in web mode too. It now uses path.relative, and still refuses .., encoded .. and a backslash escape. integration.md says the same about the CSP. dist rebuilt with Bun 1.4.2 on mote (the old source rebuilt to the committed dist byte for byte, so the dist diff is only this change). Run: - mote (macOS 27): bun run build, typecheck, bun test: 33 pass. - win-run (Windows 11): bun test: 33 pass. - Linux, the real app: a dev magpie (-tags dev,gtk3) in WSL magpie-desktop under a sandbox HOME, with this plugin installed. Old plugin: the frame reached the service and no script ran, blank. New: the service page rendered and connected to magpie. - macOS, a WKWebView with a wails:// scheme over a real dev backend on mote, sandboxed frame: renders with the old and the new policy. Broken by hand: - the new CSP test is red on the old server.ts (no own origin in script-src etc.); - the boot test for wails.localhost is red on the old boot.js; - the asset test is red on Windows with the old containment check. Not tried: the real Windows Wails app (WebView2) end to end, and the reporter's own machine; their platform isn't stated, and Linux is the one where this reproduces.
108 lines
4.2 KiB
JavaScript
108 lines
4.2 KiB
JavaScript
(() => {
|
|
const messages = {
|
|
en: {
|
|
title: 'Fingerprint',
|
|
connecting: 'Connecting to Fingerprint…',
|
|
remote:
|
|
'Upgrade Magpie for remote plugin services, or forward the service port to this computer over SSH.',
|
|
invalidPort: 'Invalid Fingerprint service port.',
|
|
failed: 'Could not connect',
|
|
},
|
|
'zh-Hans': {
|
|
title: '模型指纹',
|
|
connecting: '正在连接模型指纹服务…',
|
|
remote: '请升级 Magpie 以支持远程插件服务,或将服务器的服务端口通过 SSH 转发到本机。',
|
|
invalidPort: '模型指纹服务端口无效。',
|
|
failed: '连接失败',
|
|
},
|
|
'zh-Hant': {
|
|
title: '模型指紋',
|
|
connecting: '正在連線至模型指紋服務…',
|
|
remote: '請升級 Magpie 以支援遠端外掛服務,或透過 SSH 將伺服器的服務連接埠轉送至本機。',
|
|
invalidPort: '模型指紋服務連接埠無效。',
|
|
failed: '連線失敗',
|
|
},
|
|
ja: {
|
|
title: 'モデル指紋',
|
|
connecting: 'モデル指紋サービスに接続中…',
|
|
remote:
|
|
'リモートプラグインサービスを利用するには、Magpie を更新するか、SSH でサービスポートをこのコンピューターに転送してください。',
|
|
invalidPort: 'モデル指紋サービスのポートが無効です。',
|
|
failed: '接続できませんでした',
|
|
},
|
|
de: {
|
|
title: 'Modell-Fingerabdruck',
|
|
connecting: 'Verbindung zum Fingerabdruck-Dienst wird hergestellt…',
|
|
remote:
|
|
'Aktualisieren Sie Magpie für entfernte Plugin-Dienste oder leiten Sie den Dienstport per SSH an diesen Computer weiter.',
|
|
invalidPort: 'Ungültiger Port für den Fingerabdruck-Dienst.',
|
|
failed: 'Verbindung fehlgeschlagen',
|
|
},
|
|
};
|
|
let text = messages.en;
|
|
const status = document.getElementById('status');
|
|
function followLanguage(theme) {
|
|
const language = String(theme?.lang || 'en')
|
|
.toLowerCase()
|
|
.replaceAll('_', '-');
|
|
const parts = language.split('-');
|
|
const key =
|
|
parts[0] === 'zh'
|
|
? parts.includes('hant') ||
|
|
(!parts.includes('hans') && parts.some((part) => ['tw', 'hk', 'mo'].includes(part)))
|
|
? 'zh-Hant'
|
|
: 'zh-Hans'
|
|
: parts[0];
|
|
text = messages[key] || messages.en;
|
|
document.documentElement.lang = messages[key] ? key : 'en';
|
|
document.title = text.title;
|
|
document.getElementById('title').textContent = text.title;
|
|
status.textContent = text.connecting;
|
|
}
|
|
return (async () => {
|
|
const theme = await window.magpie?.ready;
|
|
followLanguage(theme);
|
|
window.magpie?.onTheme?.(followLanguage);
|
|
const config = (await window.magpie?.options?.get?.()) || {};
|
|
const port = Number(config.port ?? 3488);
|
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(text.invalidPort);
|
|
let service = window.magpie?.service;
|
|
if (!service) {
|
|
// This computer's window: wails://localhost on macOS and Linux,
|
|
// http://wails.localhost on Windows (Wails v3, WebView2).
|
|
const host = String(location.hostname || '')
|
|
.toLowerCase()
|
|
.replace(/^\[|\]$/g, '');
|
|
const local =
|
|
!host ||
|
|
host === 'localhost' ||
|
|
host.endsWith('.localhost') ||
|
|
host === '::1' ||
|
|
/^127\./.test(host);
|
|
if (!local) {
|
|
status.textContent = text.remote;
|
|
return;
|
|
}
|
|
service = `http://127.0.0.1:${port}/`;
|
|
}
|
|
const url = new URL(service, location.href);
|
|
// Opaque Magpie web frames need the concrete proxy origin in connect-src.
|
|
url.searchParams.set('uiOrigin', url.origin);
|
|
if (theme) {
|
|
url.searchParams.set('theme', theme.dark ? 'dark' : 'light');
|
|
if (theme.lang) url.searchParams.set('lang', theme.lang);
|
|
}
|
|
const context = window.magpie?.context?.provider;
|
|
if (context?.id) url.searchParams.set('provider', context.id);
|
|
window.magpie?.onAction((action) => {
|
|
if (action?.provider?.id) {
|
|
url.searchParams.set('provider', action.provider.id);
|
|
location.replace(url.href);
|
|
}
|
|
});
|
|
location.replace(url.href);
|
|
})().catch((error) => {
|
|
status.textContent = `${text.failed}: ${String(error?.message || error)}`;
|
|
});
|
|
})();
|