Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

host: the API-key file is owner-only on Windows (a protected ACL for the current user), and the test asserts the effective ACL

Niko1221f549c31d1d99
diff --git a/apps/host/server/model-providers.mjs b/apps/host/server/model-providers.mjs
index c174b4f68..6d281eeac 100644
--- a/apps/host/server/model-providers.mjs
+++ b/apps/host/server/model-providers.mjs
@@ -1,7 +1,8 @@
/** Saved API connections. Secrets never leave the host's private credentials file. */
-import { existsSync, readFileSync, writeFileSync, renameSync, chmodSync, mkdirSync } from 'node:fs';
+import { existsSync, readFileSync, writeFileSync, renameSync, mkdirSync } from 'node:fs';
import { join } from 'node:path';
import { randomUUID } from 'node:crypto';
+import { makePrivate } from './private-file.mjs';
export const PROVIDER_CATALOG = [
{ id: 'openai', name: 'OpenAI', baseUrl: 'https://api.openai.com/v1', protocol: 'openai-responses' },
@@ -45,13 +46,13 @@ export function createModelProviders({ directory, changed = () => {}, fetchImpl
// Do not silently erase connections if a credentials file needs repair.
const saved = JSON.parse(readFileSync(file, 'utf8'));
if (!Array.isArray(saved)) fail('The model connections file is invalid.');
- connections = saved; chmodSync(file, 0o600);
+ connections = saved; makePrivate(file);
}
function list() { return { catalog: PROVIDER_CATALOG, connections: connections.map(publicConnection) }; }
function persist(next) {
const temp = `${file}.${randomUUID()}.tmp`;
writeFileSync(temp, JSON.stringify(next, null, 2), { mode: 0o600 });
- renameSync(temp, file); chmodSync(file, 0o600);
+ makePrivate(temp); renameSync(temp, file); makePrivate(file);
connections = next; changed(list()); return list();
}
function draft(body) {
diff --git a/apps/host/server/private-file.mjs b/apps/host/server/private-file.mjs
new file mode 100644
index 000000000..f8e836047
--- /dev/null
+++ b/apps/host/server/private-file.mjs
@@ -0,0 +1,24 @@
+/** Owner-only files. POSIX: mode 0600. Windows: a protected ACL naming only the current user (NTFS has no mode bits). */
+import { chmodSync } from 'node:fs';
+import { execFileSync } from 'node:child_process';
+import { join } from 'node:path';
+
+// Name the Windows tools by path: Git for Windows puts a different whoami first on PATH.
+const system32 = name => join(process.env.SystemRoot || 'C:\\Windows', 'System32', name);
+
+let userSid = null;
+/** The current user's SID, read once with whoami (language independent). */
+export function currentUserSid() {
+ if (userSid) return userSid;
+ const out = execFileSync(system32('whoami.exe'), ['/user', '/fo', 'csv', '/nh'], { encoding: 'utf8', timeout: 10000, windowsHide: true });
+ const match = /S-1-\d+(?:-\d+)+/.exec(out);
+ if (!match) throw new Error('Could not read the current Windows user.');
+ return (userSid = match[0]);
+}
+
+export function makePrivate(path, { platform = process.platform } = {}) {
+ if (platform !== 'win32') { chmodSync(path, 0o600); return; }
+ // Grant first, then drop every inherited entry, so the file is never left without an owner entry.
+ execFileSync(system32('icacls.exe'), [path, '/grant:r', `*${currentUserSid()}:F`, '/inheritance:r'],
+ { stdio: 'ignore', timeout: 15000, windowsHide: true });
+}
diff --git a/apps/host/tests/helpers/assert-private.mjs b/apps/host/tests/helpers/assert-private.mjs
new file mode 100644
index 000000000..92159b389
--- /dev/null
+++ b/apps/host/tests/helpers/assert-private.mjs
@@ -0,0 +1,14 @@
+import assert from 'node:assert/strict';
+import { statSync } from 'node:fs';
+import { execFileSync } from 'node:child_process';
+import { join } from 'node:path';
+import { currentUserSid } from '../../server/private-file.mjs';
+
+/** The effective protection of a file: mode 0600 on POSIX, the exact DACL (one protected entry for this user) on NTFS. */
+export function assertPrivate(path) {
+ if (process.platform !== 'win32') { assert.equal(statSync(path).mode & 0o777, 0o600); return; }
+ const sddl = execFileSync(join(process.env.SystemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'), ['-NoProfile', '-NonInteractive', '-Command', `(Get-Acl -LiteralPath '${path.replace(/'/g, "''")}').Sddl`],
+ { encoding: 'utf8', timeout: 30000, windowsHide: true }).trim();
+ const dacl = sddl.slice(sddl.indexOf('D:'));
+ assert.equal(dacl, `D:PAI(A;;FA;;;${currentUserSid()})`, `ACL is not owner-only: ${sddl}`);
+}
diff --git a/apps/host/tests/model-providers.test.mjs b/apps/host/tests/model-providers.test.mjs
index 43208001c..eee2bc303 100644
--- a/apps/host/tests/model-providers.test.mjs
+++ b/apps/host/tests/model-providers.test.mjs
@@ -1,10 +1,11 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { mkdtempSync, readFileSync, statSync, rmSync } from 'node:fs';
+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { createModelProviders, normalizeBaseUrl, PROVIDER_CATALOG } from '../server/model-providers.mjs';
import { createMockModelApi } from './mock-model-api.mjs';
+import { assertPrivate } from './helpers/assert-private.mjs';
test('connections persist, redact keys, retain unchanged keys, and validate endpoints/models', async t => {
const directory = mkdtempSync(join(tmpdir(), 'strata-providers-'));
@@ -14,7 +15,7 @@ test('connections persist, redact keys, retain unchanged keys, and validate endp
const saved = service.save(draft).connections[0];
assert.equal(saved.baseUrl, 'http://192.168.1.20:1234/v1');
assert.equal(saved.apiKeySet, true); assert.equal('apiKey' in saved, false);
- assert.equal(statSync(join(directory, 'model-providers.json')).mode & 0o777, 0o600);
+ assertPrivate(join(directory, 'model-providers.json'));
service.save({ ...saved, apiKey: '' });
assert.equal(JSON.parse(readFileSync(join(directory, 'model-providers.json')))[0].apiKey, 'test-key');
const reopened = createModelProviders({ directory });