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++

App sharing: the shared and tunnel address answers a browser's CORS preflight and sends Access-Control headers when an API key is set; without a key nothing changes (PR #3853 by MaKla89, #3208)

MaKla89eb1c40038c0b
diff --git a/apps/host/server/local-share.mjs b/apps/host/server/local-share.mjs
index bcbfc2c4c..e8659c61c 100644
--- a/apps/host/server/local-share.mjs
+++ b/apps/host/server/local-share.mjs
@@ -14,8 +14,22 @@ export function createLocalShare({ handle, hasKey, changed = () => {}, host = '0
if (listener) throw new Error('Sharing is already starting.');
listener = http.createServer(async (req, res) => {
const path = apiPath(new URL(req.url ?? '/', 'http://localhost').pathname);
+ const method = req.method ?? 'GET';
+ // #3208: with an API key set, a browser page of any site can call the shared API - the key decides, not the
+ // origin. The browser's preflight (OPTIONS) never carries the key (the spec says so), so it is answered here,
+ // before the path check and the key check; the real request that follows still goes through both. Without a
+ // key no CORS headers go out, as before: the listener stays "a device on this network" (SECURITY.md), and a
+ // web page of another site on the internet cannot read the model through it.
+ if (hasKey()) {
+ res.setHeader('access-control-allow-origin', '*');
+ res.setHeader('access-control-allow-methods', 'GET, POST, OPTIONS');
+ // the headers the preflight asks for (SDKs add their own; Anthropic browser clients send anthropic-version)
+ res.setHeader('access-control-allow-headers', String(req.headers['access-control-request-headers'] ?? '') || 'authorization, content-type, x-api-key, x-strata-client, anthropic-version, anthropic-beta');
+ res.setHeader('access-control-max-age', '600');
+ if (method === 'OPTIONS') { res.writeHead(204); res.end(); return; }
+ }
if (!['/v1/models','/v1/chat/completions','/v1/messages'].includes(path)) { res.writeHead(404); res.end('Not found'); return; }
- try { await handle(req, res, path, req.method ?? 'GET'); }
+ try { await handle(req, res, path, method); }
catch { if (!res.headersSent) res.writeHead(500); res.end('Request failed'); }
});
try { await new Promise((resolve,reject) => { listener.once('error',reject); listener.listen(port,host,resolve); }); }
diff --git a/apps/host/tests/cors-share.test.mjs b/apps/host/tests/cors-share.test.mjs
new file mode 100644
index 000000000..dd2552a04
--- /dev/null
+++ b/apps/host/tests/cors-share.test.mjs
@@ -0,0 +1,83 @@
+// #3208: the local-network share listener answers browser CORS the way the app's own API does - when an API key is set.
+// The reporter's chatbot page (a browser on another machine) could not get past the preflight: OPTIONS carries no key
+// (the spec says so), openai() checks the key first, so every preflight got 401 and no answer had a CORS header.
+// Without a key the listener sends no CORS headers, so it stays "a device on this network" (SECURITY.md).
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { createLocalShare } from '../server/local-share.mjs';
+
+/** openai() as index.mjs runs it: the key check first (no key set means every client passes), then path and method. */
+const openaiLike = key => (req, res, path, method) => {
+ if (key && req.headers.authorization !== 'Bearer test-only-key') {
+ res.writeHead(401, { 'content-type': 'application/json' });
+ res.end('{"error":"Invalid API key"}');
+ return;
+ }
+ if (path === '/v1/models' && method === 'GET') {
+ res.writeHead(200, { 'content-type': 'application/json' });
+ res.end('{"object":"list","data":[]}');
+ return;
+ }
+ res.writeHead(404, { 'content-type': 'application/json' });
+ res.end('{"error":"No route"}');
+};
+
+const preflight = (root, origin, extra = {}) => fetch(`${root}/v1/models`, {
+ method: 'OPTIONS',
+ headers: { origin, 'access-control-request-method': 'GET', ...extra },
+});
+
+test('with a key, the shared listener answers the preflight without one and allows any origin', async () => {
+ const share = createLocalShare({ handle: openaiLike(true), hasKey: () => true, host: '127.0.0.1', port: 0 });
+ try {
+ const { url } = await share.start();
+ const root = url.replace(/\/v1$/, '');
+ const res = await preflight(root, 'http://192.168.1.20:9999', { 'access-control-request-headers': 'authorization,content-type' });
+ assert.equal(res.status, 204);
+ assert.equal(res.headers.get('access-control-allow-origin'), '*');
+ assert.match(res.headers.get('access-control-allow-methods'), /OPTIONS/);
+ assert.equal(res.headers.get('access-control-allow-headers'), 'authorization,content-type');
+ assert.equal(res.headers.get('access-control-max-age'), '600');
+ // a preflight that asks for nothing still names the headers the SDKs and Anthropic browser clients send
+ const plain = await preflight(root, 'http://example.org');
+ assert.match(plain.headers.get('access-control-allow-headers'), /authorization/);
+ assert.match(plain.headers.get('access-control-allow-headers'), /anthropic-version/);
+ } finally { await share.stop(); }
+});
+
+test('with a key, real answers carry Access-Control-Allow-Origin too - the 401 for a missing key as well', async () => {
+ const share = createLocalShare({ handle: openaiLike(true), hasKey: () => true, host: '127.0.0.1', port: 0 });
+ try {
+ const { url } = await share.start();
+ const ok = await fetch(url + '/models', { headers: { origin: 'http://example.org', authorization: 'Bearer test-only-key' } });
+ assert.equal(ok.status, 200);
+ assert.equal(ok.headers.get('access-control-allow-origin'), '*');
+ const denied = await fetch(url + '/models', { headers: { origin: 'http://example.org' } });
+ assert.equal(denied.status, 401);
+ assert.equal(denied.headers.get('access-control-allow-origin'), '*', 'the browser must see the real 401, not a CORS wall');
+ } finally { await share.stop(); }
+});
+
+test('a preflight grants nothing: the shared listener still answers no host control, only inference', async () => {
+ const share = createLocalShare({ handle: openaiLike(true), hasKey: () => true, host: '127.0.0.1', port: 0 });
+ try {
+ const { url } = await share.start();
+ const root = url.replace(/\/v1$/, '');
+ assert.equal((await fetch(root + '/api/tasks', { method: 'OPTIONS', headers: { origin: 'http://example.org' } })).status, 204);
+ assert.equal((await fetch(root + '/api/tasks', { headers: { authorization: 'Bearer test-only-key' } })).status, 404);
+ } finally { await share.stop(); }
+});
+
+test('without a key nothing changes: no CORS headers, and the preflight falls through as before', async () => {
+ const share = createLocalShare({ handle: openaiLike(false), hasKey: () => false, host: '127.0.0.1', port: 0 });
+ try {
+ const { url } = await share.start();
+ const root = url.replace(/\/v1$/, '');
+ const pre = await preflight(root, 'http://example.org', { 'access-control-request-headers': 'authorization,content-type' });
+ assert.equal(pre.status, 404, 'OPTIONS /v1/models reaches the route check, as before the fix');
+ assert.equal(pre.headers.get('access-control-allow-origin'), null);
+ const get = await fetch(url + '/models', { headers: { origin: 'http://example.org' } });
+ assert.equal(get.status, 200, 'a device on the network still uses the keyless share');
+ assert.equal(get.headers.get('access-control-allow-origin'), null, 'a keyless share never lets a web page of another site read the model');
+ } finally { await share.stop(); }
+});
diff --git a/docs/DETAILS.md b/docs/DETAILS.md
index 43538ddca..4255fc626 100644
--- a/docs/DETAILS.md
+++ b/docs/DETAILS.md
@@ -552,7 +552,10 @@ tables per token). The scaling is fixed for the whole run, because the KV cache
- **Browser pages (CORS):** off by default. `"cors_origins": ["https://chat.example.com"]` lets those origins call `/v1/*`;
`["*"]` lets any page and is only sensible with an API key. It never opens `/settings`, `/unload` or the MCP tools. It
belongs to the engine's own server; the desktop app answers browser pages on its own API address and already allows
- pages of any site there.
+ pages of any site there. When you share with other devices or run a tunnel, the shared address answers them too, with an
+ API key: the key decides, not the site. The browser's preflight (`OPTIONS`) is answered without a key, since a browser never
+ sends one with it; the request that follows still needs the key. Without an API key the shared address sends no CORS
+ headers, so a page of another site cannot read your model through it - only devices on your network can.
- **Host names (DNS rebinding):** without an API key the server answers only requests whose `Host` is `localhost`, an IP
address, the address it listens on, or (when it listens beyond this PC) this PC's name and `host.docker.internal`. Others
get **403** naming the setting. Add a name with `"allowed_hosts": ["strata.example.com"]` or