Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(settings): Preserve Custom STT endpoint URL across provider tabs

Chadpiha1462c23dd4fc
diff --git a/src/components/TranscriptionModelPicker.tsx b/src/components/TranscriptionModelPicker.tsx
index e57c6f2db..1f8288417 100644
--- a/src/components/TranscriptionModelPicker.tsx
+++ b/src/components/TranscriptionModelPicker.tsx
@@ -631,6 +631,9 @@ export default function TranscriptionModelPicker({
[onModeChange, ensureValidCloudSelection]
);
+ // Never writes cloudTranscriptionBaseUrl: that key is the Custom tab's only
+ // storage, and built-in providers resolve their endpoints from the registry
+ // at request time — writing it here destroyed the user's URL (#1459).
const handleCloudProviderChange = useCallback(
(providerId: string) => {
onCloudProviderSelect(providerId);
@@ -641,14 +644,11 @@ export default function TranscriptionModelPicker({
return;
}
- if (provider) {
- setCloudTranscriptionBaseUrl?.(provider.baseUrl);
- if (provider.models?.length) {
- onCloudModelSelect(provider.models[0].id);
- }
+ if (provider?.models?.length) {
+ onCloudModelSelect(provider.models[0].id);
}
},
- [cloudProviders, onCloudProviderSelect, onCloudModelSelect, setCloudTranscriptionBaseUrl]
+ [cloudProviders, onCloudProviderSelect, onCloudModelSelect]
);
const handleLocalProviderChange = useCallback(
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index efef900cc..99f88985a 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -36,8 +36,10 @@ import { recordCleanupFailure } from "../stores/cleanupFailureStore";
import {
getBatchTranscriptionModel,
getTranscriptionProvider,
+ getTranscriptionProviders,
isOnlineParakeetModel,
} from "../models/ModelRegistry";
+import { isTinfoilInferenceUrl } from "../services/transcriptionBaseUrl";
import { shouldSkipTranscriptionApiKey } from "./transcriptionAuth";
import {
isSelfHostedTranscription,
@@ -2892,6 +2894,18 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
}
}
+ // The provider-id guard above can't catch a Custom base URL that points at
+ // Tinfoil's inference host (e.g. persisted by the pre-#1459 tab clobber) —
+ // check the URL too. Must stay outside the try below: its catch swallows
+ // errors into the OpenAI default endpoint.
+ if (
+ currentProvider === "custom" &&
+ !isSelfHosted &&
+ isTinfoilInferenceUrl(currentBaseUrl, getTranscriptionProviders())
+ ) {
+ throw new Error("Tinfoil transcription must go through the attested main-process proxy");
+ }
+
if (
this.cachedTranscriptionEndpoint &&
(this.cachedEndpointProvider !== currentProvider ||
diff --git a/src/services/fileTranscription.ts b/src/services/fileTranscription.ts
index 7e6e66d84..8b326d7ab 100644
--- a/src/services/fileTranscription.ts
+++ b/src/services/fileTranscription.ts
@@ -1,4 +1,6 @@
import { withSessionRefresh } from "../lib/auth";
+import { getTranscriptionProviders } from "../models/ModelRegistry";
+import { isTinfoilInferenceUrl, resolveByokBaseUrl } from "./transcriptionBaseUrl";
export interface FileTranscriptionResult {
success: boolean;
@@ -61,12 +63,31 @@ export async function transcribeFile(
});
}
+ // Built-in providers resolve from the registry; only Custom uses the
+ // stored URL, which provider tab switches no longer overwrite (#1459).
+ const providers = getTranscriptionProviders();
+ const baseUrl = resolveByokBaseUrl(
+ cfg.cloudTranscriptionProvider,
+ cfg.cloudTranscriptionBaseUrl || "",
+ providers
+ );
+ // A Custom URL pointing at Tinfoil (e.g. persisted by the pre-#1459 tab
+ // clobber) must not bypass the attested main-process proxy. Self-hosted
+ // mode is exempt: the handler routes it to remoteTranscriptionUrl.
+ if (
+ cfg.cloudTranscriptionProvider === "custom" &&
+ cfg.transcriptionMode !== "self-hosted" &&
+ isTinfoilInferenceUrl(baseUrl, providers)
+ ) {
+ throw new Error("Tinfoil transcription must go through the attested main-process proxy");
+ }
+
// Self-hosted fields make the handler route to the configured server
// (fail-closed on misconfiguration) instead of stale BYOK settings.
return window.electronAPI.transcribeAudioFileByok!({
filePath,
apiKey: cfg.getApiKey(),
- baseUrl: cfg.cloudTranscriptionBaseUrl || "",
+ baseUrl,
model: cfg.cloudTranscriptionModel,
diarize: diarize || undefined,
provider: cfg.cloudTranscriptionProvider,
diff --git a/src/services/transcriptionBaseUrl.ts b/src/services/transcriptionBaseUrl.ts
new file mode 100644
index 000000000..dffddf3c8
--- /dev/null
+++ b/src/services/transcriptionBaseUrl.ts
@@ -0,0 +1,47 @@
+// Pure BYOK base-URL resolution, kept free of registry imports so tests can
+// load it standalone (see test/services/transcriptionBaseUrl.test.js).
+//
+// `cloudTranscriptionBaseUrl` is owned by the Custom provider tab: it is the
+// only place a user-typed endpoint lives, so built-in providers must resolve
+// their endpoints from the registry instead of trusting that key (#1459).
+export interface TranscriptionProviderBaseUrl {
+ id: string;
+ baseUrl: string;
+}
+
+export function resolveByokBaseUrl(
+ providerId: string,
+ storedBaseUrl: string,
+ providers: readonly TranscriptionProviderBaseUrl[]
+): string {
+ if (providerId === "custom") return storedBaseUrl;
+ return providers.find((p) => p.id === providerId)?.baseUrl || "";
+}
+
+function parseHostname(url: string): string | null {
+ for (const candidate of [url, `https://${url}`]) {
+ try {
+ return new URL(candidate).hostname;
+ } catch {
+ // fall through to the protocol-prefixed retry
+ }
+ }
+ return null;
+}
+
+/**
+ * True when a URL points at Tinfoil's inference host. Tinfoil audio must go
+ * through the attested main-process proxy, so request paths use this to
+ * refuse a Custom-provider base URL that targets Tinfoil directly.
+ */
+export function isTinfoilInferenceUrl(
+ url: string,
+ providers: readonly TranscriptionProviderBaseUrl[]
+): boolean {
+ const tinfoilBaseUrl = providers.find((p) => p.id === "tinfoil")?.baseUrl;
+ if (!tinfoilBaseUrl || !url) return false;
+
+ const tinfoilHost = parseHostname(tinfoilBaseUrl);
+ const candidateHost = parseHostname(url);
+ return tinfoilHost !== null && candidateHost === tinfoilHost;
+}
diff --git a/test/services/transcriptionBaseUrl.test.js b/test/services/transcriptionBaseUrl.test.js
new file mode 100644
index 000000000..36c023ad2
--- /dev/null
+++ b/test/services/transcriptionBaseUrl.test.js
@@ -0,0 +1,76 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const path = require("node:path");
+const ts = require("typescript");
+
+let loaded;
+const load = () => {
+ if (!loaded) {
+ const filename = path.join(__dirname, "../../src/services/transcriptionBaseUrl.ts");
+ const source = fs.readFileSync(filename, "utf8");
+ const output = ts.transpileModule(source, {
+ compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
+ }).outputText;
+ loaded = import(`data:text/javascript;base64,${Buffer.from(output).toString("base64")}`);
+ }
+ return loaded;
+};
+
+const PROVIDERS = [
+ { id: "openai", baseUrl: "https://api.openai.com/v1" },
+ { id: "groq", baseUrl: "https://api.groq.com/openai/v1" },
+ { id: "mistral", baseUrl: "https://api.mistral.ai/v1" },
+ { id: "tinfoil", baseUrl: "https://inference.tinfoil.sh/v1" },
+];
+
+test("custom provider resolves to the stored URL, untouched", async () => {
+ const { resolveByokBaseUrl } = await load();
+ assert.equal(
+ resolveByokBaseUrl("custom", "http://127.0.0.1:8587/v1", PROVIDERS),
+ "http://127.0.0.1:8587/v1"
+ );
+});
+
+test("built-in provider resolves from the registry, ignoring a stored custom URL", async () => {
+ const { resolveByokBaseUrl } = await load();
+ assert.equal(
+ resolveByokBaseUrl("groq", "http://127.0.0.1:8587/v1", PROVIDERS),
+ "https://api.groq.com/openai/v1"
+ );
+});
+
+test("unknown provider resolves to empty so callers fail closed", async () => {
+ const { resolveByokBaseUrl } = await load();
+ assert.equal(resolveByokBaseUrl("nonexistent", "http://127.0.0.1:8587/v1", PROVIDERS), "");
+});
+
+test("detects Tinfoil's inference host regardless of path or trailing slash", async () => {
+ const { isTinfoilInferenceUrl } = await load();
+ assert.equal(isTinfoilInferenceUrl("https://inference.tinfoil.sh/v1", PROVIDERS), true);
+ assert.equal(isTinfoilInferenceUrl("https://inference.tinfoil.sh/v1/", PROVIDERS), true);
+ assert.equal(
+ isTinfoilInferenceUrl("https://inference.tinfoil.sh/v1/audio/transcriptions", PROVIDERS),
+ true
+ );
+});
+
+test("detects Tinfoil's inference host when the protocol is omitted", async () => {
+ const { isTinfoilInferenceUrl } = await load();
+ assert.equal(isTinfoilInferenceUrl("inference.tinfoil.sh/v1", PROVIDERS), true);
+});
+
+test("does not flag other hosts, lookalike hosts, or garbage input", async () => {
+ const { isTinfoilInferenceUrl } = await load();
+ assert.equal(isTinfoilInferenceUrl("https://api.openai.com/v1", PROVIDERS), false);
+ assert.equal(isTinfoilInferenceUrl("https://inference.tinfoil.sh.evil.com/v1", PROVIDERS), false);
+ assert.equal(isTinfoilInferenceUrl("http://127.0.0.1:8587/v1", PROVIDERS), false);
+ assert.equal(isTinfoilInferenceUrl("", PROVIDERS), false);
+ assert.equal(isTinfoilInferenceUrl("::not a url::", PROVIDERS), false);
+});
+
+test("never flags anything when Tinfoil is absent from the provider list", async () => {
+ const { isTinfoilInferenceUrl } = await load();
+ const withoutTinfoil = PROVIDERS.filter((p) => p.id !== "tinfoil");
+ assert.equal(isTinfoilInferenceUrl("https://inference.tinfoil.sh/v1", withoutTinfoil), false);
+});