فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A07): validate native Tauri WebView2 origin and reject remotely hosted UI

davoodmehraban89 committed Oct 16, 2026 at 19:09 UTC 6275b1d37017ae4d45b37247718afb87126afdc0
1 file changed +17
tests/windows-vm-native-origin.cjs new
+17
@@ -0,0 +1,17 @@
1 +'use strict';
2 +// Trust boundary for installed Windows Tauri: the application UI must be
3 +// served by Tauri's own local origin, never by a remote domain.
4 +function verifyNativeOrigin(href) {
5 + let url;
6 + try { url = new URL(href); }
7 + catch { throw Error('Installed WebView2 did not expose a valid document URL'); }
8 + const tauriHttp = (url.protocol === 'http:' || url.protocol === 'https:') &&
9 + url.hostname === 'tauri.localhost' && !url.username && !url.password;
10 + const tauriScheme = url.protocol === 'tauri:' && url.hostname === 'localhost' &&
11 + !url.username && !url.password;
12 + if (!tauriHttp && !tauriScheme) {
13 + throw Error('Installed WebView2 unexpectedly loaded a non-Tauri application origin');
14 + }
15 + return url.origin;
16 +}
17 +module.exports = { verifyNativeOrigin };