فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A07): verify actual native WebView2 Tauri origin during Windows VM runs
* test(A07): validate native Tauri WebView2 origin and reject remotely hosted UI * test(A07): prove installed WebView2 loads Tauri local UI and report full origin * test(A07): exercise correct WebView2 origin parsing and remote-origin rejection * ci(A07): run real NSIS Windows lab when native origin checks change * fix(test): correctly report custom tauri://localhost origin without null serialization
davoodmehraban89 committed
Oct 16, 2026 at 19:19 UTC
ea4460a167ce33f739e9152fbdf377c4cbd7cb9f
4 files changed
+52
-1
.github/workflows/windows-vm-native-lab.yml
+2
@@ -10,6 +10,8 @@ on:
10
- 'package.json'
11
- 'package-lock.json'
12
- 'tests/windows-vm-installed-tauri-cdp.cjs'
13
+ - 'tests/windows-vm-native-origin.cjs'
14
+ - 'tests/windows-vm-native-origin.test.mjs'
15
- 'tests/windows-vm-native-functional-matrix.cjs'
16
- 'scripts/windows-vm-native-lab.ps1'
17
- 'scripts/windows-vm-set-candidate.cjs'
tests/windows-vm-installed-tauri-cdp.cjs
+2
-1
@@ -7,6 +7,7 @@ const fs = require('node:fs');
7
const path = require('node:path');
8
const { spawn, execFileSync } = require('node:child_process');
9
const verifyNativeFunctionalMatrix = require('./windows-vm-native-functional-matrix.cjs');
10
+const { verifyNativeOrigin } = require('./windows-vm-native-origin.cjs');
11
12
const [exe, profile, mode, expectedVersion, reportPath] = process.argv.slice(2);
13
assert.equal(process.platform, 'win32');
@@ -129,7 +130,7 @@ async function connect(url) {
130
'(function(){return window.FINORA && document.getElementById("finoraAuthOverlay") && !!globalThis.__TAURI_INTERNALS__?.invoke ? { title:document.title, version:window.FINORA.version, href:location.href, initialMode:document.getElementById("faTitle").textContent, databaseReady:true } : null})()'
131
), 65000);
132
report.installedNativeTauri = true;
132
- report.browserOrigin = ready.href.replace(/[/#?].*$/, '');
133
+ report.browserOrigin = verifyNativeOrigin(ready.href);
134
report.displayedVersion = ready.version;
135
report.versionMatchesPackage = ready.version === expectedVersion;
136
// Verified against git tag v2.0.3: that shipped src/main.js hardcodes
tests/windows-vm-native-origin.cjs
new
+19
@@ -0,0 +1,19 @@
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
+ // URL.origin is "null" for custom schemes in JavaScript; preserve Tauri's
16
+ // validated local custom origin explicitly rather than reporting "null".
17
+ return tauriScheme ? 'tauri://localhost' : url.origin;
18
+}
19
+module.exports = { verifyNativeOrigin };
tests/windows-vm-native-origin.test.mjs
new
+29
@@ -0,0 +1,29 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { createRequire } from 'node:module';
4
+const require = createRequire(import.meta.url);
5
+const { verifyNativeOrigin } = require('./windows-vm-native-origin.cjs');
6
+
7
+test('A07: accepts only packaged Tauri local document origins', () => {
8
+ assert.equal(verifyNativeOrigin('http://tauri.localhost/#dashboard'),
9
+ 'http://tauri.localhost');
10
+ assert.equal(verifyNativeOrigin('https://tauri.localhost/invoices?test=1'),
11
+ 'https://tauri.localhost');
12
+ const scheme = verifyNativeOrigin('tauri://localhost/index.html');
13
+ assert.ok(scheme.startsWith('tauri:'));
14
+});
15
+
16
+test('A07: rejects remote origins, deceptive subdomains, credentials and malformed URLs', () => {
17
+ for (const url of [
18
+ 'https://some-remote-service.example/login',
19
+ 'https://tauri.localhost.attack.test/',
20
+ 'http://localhost:4173/',
21
+ 'https://tauri.localhost@attacker.example/',
22
+ 'https://bob:secret@tauri.localhost/',
23
+ 'about:blank', 'file:///c:/windows/system32',
24
+ '//tauri.localhost/dashboard',
25
+ 'bad-url'
26
+ ]) {
27
+ assert.throws(() => verifyNativeOrigin(url), Error, url);
28
+ }
29
+});