The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Own key: a key is sent over http:// only to this computer (#234)
riverisbuilding362078b60cda
diff --git a/.changeset/own-key-http-local.md b/.changeset/own-key-http-local.mdnew file mode 100644index 0000000..c2ce787--- /dev/null+++ b/.changeset/own-key-http-local.md@@ -0,0 +1,5 @@+---+"@openfilm/desktop": patch+---++Own key: a key is sent over http:// only to this computer (localhost, 127.0.0.1, ::1), as the form says. Any other http:// address is refused before the key is sent in the clear.diff --git a/apps/desktop/src/agent-roster.mjs b/apps/desktop/src/agent-roster.mjsindex 9617bbc..907fa13 100644--- a/apps/desktop/src/agent-roster.mjs+++ b/apps/desktop/src/agent-roster.mjs@@ -133,6 +133,19 @@ function writeChoices(dataDir, choices) {writeFileSync(join(dataDir, 'agents.json'), `${JSON.stringify(choices, null, 2)}\n`);}+/**+ * Whether a key may be sent to `baseUrl`: over https://, or over http:// only to this computer (localhost, 127.x.x.x,+ * ::1), where it crosses no network in the clear.+ */+export function keyAddress(baseUrl) {+ if (/\s/.test(baseUrl)) return false;+ let url;+ try { url = new URL(baseUrl); } catch { return false; }+ if (url.protocol === 'https:') return true;+ const host = url.hostname.replace(/^\[|\]$/g, '').toLowerCase();+ return url.protocol === 'http:' && (host === 'localhost' || host.endsWith('.localhost') || host === '::1' || /^127(\.\d{1,3}){3}$/.test(host));+}+/** One request, in the format's own shape, carrying a picture. */export function probeRequest(format, baseUrl, key, model) {const base = baseUrl.replace(/\/+$/, '');@@ -413,7 +426,7 @@ export function createRoster(deps) {const format = BYOK_FORMATS[config?.format];if (!format) return { ok: false, error: 'Choose the API format.' };const baseUrl = String(config.baseUrl || format.baseUrl).trim().replace(/\/+$/, '');- if (!/^https?:\/\/[^\s]+$/.test(baseUrl)) return { ok: false, error: 'The address has to start with https:// (or http:// for one on this computer).' };+ if (!keyAddress(baseUrl)) return { ok: false, error: 'The address has to start with https:// (or http:// for one on this computer).' };const model = String(config.model ?? '').trim();if (!model) return { ok: false, error: 'Name the model.' };const models = choices.byok?.models ?? [];diff --git a/apps/desktop/src/agent-roster.test.mjs b/apps/desktop/src/agent-roster.test.mjsindex e75345d..3c8c123 100644--- a/apps/desktop/src/agent-roster.test.mjs+++ b/apps/desktop/src/agent-roster.test.mjs@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { createRoster, probeRequest, readChoices } from './agent-roster.mjs';+import { createRoster, keyAddress, probeRequest, readChoices } from './agent-roster.mjs';const roster = (dataDir, fetch, extra = {}) => createRoster({dataDir,@@ -70,6 +70,19 @@ test('an address that answers with a web page is said so, not shown as its HTML,assert.equal(readChoices(dir).byok, null, 'nothing kept');});+test('a key goes over https://, or over http:// only to this computer; another http:// address is refused before any request', async () => {+ for (const ok of ['https://api.example.com/v1', 'http://localhost:11434/v1', 'http://127.0.0.1:1234', 'http://[::1]:8080/v1', 'http://models.localhost/v1']) {+ assert.equal(keyAddress(ok), true, ok);+ }+ for (const no of ['http://example.com/v1', 'http://192.168.1.20:11434/v1', 'http://localhost.example.com', 'ftp://127.0.0.1', 'https://api.example.com/v 1', 'api.example.com']) {+ assert.equal(keyAddress(no), false, no);+ }+ let asked = 0;+ const r = roster(mkdtempSync(join(tmpdir(), 'of-roster-')), async () => { asked++; return new Response('{}', { status: 200 }); });+ assert.match((await r.saveOwnModel({ format: 'responses', baseUrl: 'http://example.com/v1', model: 'test', key: 'x' })).error, /https:\/\//);+ assert.equal(asked, 0, 'the key was not sent');+});+test('each model is its own service with its own key; a key left empty is the one of another model on that address', async () => {const dir = mkdtempSync(join(tmpdir(), 'of-roster-'));const r = roster(dir, async () => new Response('{}', { status: 200 }));