This commit is contained in:
+28
-2
@@ -22,7 +22,7 @@ import { setSessionManager } from '../engine/tools/browser.js';
|
||||
import { setUserFolderToolDeps } from '../engine/tools/user-folder.js';
|
||||
import { setSkillToolDeps } from '../engine/tools/skills.js';
|
||||
import { setAppDocsDeps } from '../engine/tools/app-docs.js';
|
||||
import { setupAuth, requireAuth, requireAdmin } from './auth.js';
|
||||
import { setupAuth, requireAuth, requireAdmin, isProviderConfigured } from './auth.js';
|
||||
import { canUserSeeTask } from './visibility.js';
|
||||
import { mountAdminApi } from './admin-api.js';
|
||||
import { createAdminGatewayApi } from './admin-gateway-api.js';
|
||||
@@ -219,7 +219,33 @@ export function createCoreServer(opts: CoreServerOptions): {
|
||||
app.use('/api/local/reflection', express.json());
|
||||
|
||||
// === Auth setup ===
|
||||
const authActive = !!(opts.authConfig?.providers);
|
||||
// Auth activates when a provider is COMPLETELY configured (clientId +
|
||||
// clientSecret + callbackUrl, plus baseUrl for Gitea).
|
||||
//
|
||||
// FAIL CLOSED on a partial config: if the operator clearly INTENDED auth
|
||||
// (a provider has a client_id) but it's incomplete (typo'd / missing
|
||||
// secret/callback), we must NOT silently fall back to no-auth — that would
|
||||
// fail OPEN and expose /api/local, /api/config, etc. without authentication.
|
||||
// Refuse to start instead, with a clear message. (A bare `auth` block with no
|
||||
// client_id at all is treated as genuine no-auth mode.)
|
||||
const _authProviders = opts.authConfig?.providers;
|
||||
const authUsable =
|
||||
isProviderConfigured(_authProviders?.google, 'google') ||
|
||||
isProviderConfigured(_authProviders?.gitea, 'gitea');
|
||||
// "Intended" = ANY OAuth field is present on a provider (not just client_id).
|
||||
// Saving only client_secret/callback_url/base_url, or clearing client_id by
|
||||
// mistake, must still fail closed rather than drop to no-auth.
|
||||
const _hasAnyField = (p?: { clientId?: string; clientSecret?: string; callbackUrl?: string; baseUrl?: string }) =>
|
||||
!!(p?.clientId || p?.clientSecret || p?.callbackUrl || p?.baseUrl);
|
||||
const authIntended = _hasAnyField(_authProviders?.google) || _hasAnyField(_authProviders?.gitea);
|
||||
if (authIntended && !authUsable) {
|
||||
throw new Error(
|
||||
'[auth] auth is partially configured: a provider has a client_id but is missing ' +
|
||||
'client_secret / callback_url (Gitea also needs base_url). Refusing to start in an ' +
|
||||
'insecure no-auth state — complete the provider config or remove it from config.yaml.',
|
||||
);
|
||||
}
|
||||
const authActive = authUsable;
|
||||
let authenticateUpgrade: import('./auth.js').UpgradeAuthChecker | undefined;
|
||||
|
||||
if (authActive) {
|
||||
|
||||
Reference in New Issue
Block a user