mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 15:02:04 +00:00
Making `=true` grant nothing would stop a single-user self-host's local model on a patch update. It is deprecated for one release cycle instead, in a narrowed and safe form: it still grants a private host, but only to the operator's own configurations (the instance-wide admin provider and AI settings saved on an admin account), and only through the pinned operator-approved dispatcher, so redirects stay forbidden and metadata, link-local and unspecified addresses stay refused. A non-admin account's own base URL needs an exact origin in AI_PRIVATE_ORIGINS. Provider resolution passes the owning account's role to the client (`operatorTrusted`); the save route and the connection test apply the same rule to the account being configured. The boot summary now says the setting is deprecated and names the replacement, and the admin AI settings page shows the exact AI_PRIVATE_ORIGINS line for the private origins saved on the instance (every account's Local and gateway URL and the admin base URL, scheme, host and port only), so the operator can copy it and drop the old setting.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
/**
|
|
* v1.39.3 — what the deprecated `ALLOW_LOCAL_AI_PRIVATE_HOSTS=true` is
|
|
* currently standing in for, for the admin AI settings page.
|
|
*
|
|
* Null when `true` is not set. Otherwise the distinct origins of every saved
|
|
* AI base URL on the instance (each account's Local and gateway URL, and the
|
|
* instance-wide admin base URL) that point at the operator's network and that
|
|
* no `AI_PRIVATE_ORIGINS` or legacy host-list entry covers yet. Listing them is
|
|
* the migration path: the operator copies them into `AI_PRIVATE_ORIGINS`, and
|
|
* `=true` can go. A non-admin account's URL is included on purpose; `=true` no
|
|
* longer covers it, so it is exactly the one that needs an entry.
|
|
*
|
|
* An origin is scheme, host and port, nothing more, so no path or credential
|
|
* a person typed into a base URL reaches the page.
|
|
*/
|
|
import { prisma } from "@/lib/db";
|
|
import {
|
|
legacyAnyHostConfigured,
|
|
originNeedingAiGrant,
|
|
} from "@/lib/ai/local-host-allowlist";
|
|
|
|
export interface LegacyPrivateHostReport {
|
|
originsInUse: string[];
|
|
}
|
|
|
|
export async function legacyPrivateHostReport(
|
|
adminBaseUrl: string | null | undefined,
|
|
): Promise<LegacyPrivateHostReport | null> {
|
|
if (!legacyAnyHostConfigured()) return null;
|
|
const rows = await prisma.user.findMany({
|
|
where: {
|
|
OR: [{ aiBaseUrl: { not: null } }, { aiCompatBaseUrl: { not: null } }],
|
|
},
|
|
select: { aiBaseUrl: true, aiCompatBaseUrl: true },
|
|
});
|
|
const origins = new Set<string>();
|
|
for (const url of [
|
|
adminBaseUrl,
|
|
...rows.flatMap((r) => [r.aiBaseUrl, r.aiCompatBaseUrl]),
|
|
]) {
|
|
if (!url) continue;
|
|
const origin = originNeedingAiGrant(url);
|
|
if (origin) origins.add(origin);
|
|
}
|
|
return { originsInUse: [...origins].sort() };
|
|
}
|