From 9b3ae08ece7c200286efe948c90d3d357c3042e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Guti=C3=A9rrez=20Hermoso?= Date: Fri, 26 Jul 2024 12:31:43 -0400 Subject: [PATCH] create: hard-code the default session secret even more The problem here is that making it this optional meant that it wasn't supplied by [the enterprise creation function](https://github.com/gristlabs/grist-ee/blob/fb22d94878a539ec9f1085fa9ac12936ccb68dca/ext/app/server/lib/create.ts#L10). This resulted in an odd situation where the secret was required for the enterprise edition, even though it offers no additional security. Without this key, the enterprise code crashes. The requirement to supply a secret key would make a Grist instance crash if you start in normal mode but switch to enterprise, as the enterprise creator does not supply a default secret key. --- app/server/lib/BootProbes.ts | 2 +- app/server/lib/ICreate.ts | 9 ++++----- app/server/lib/coreCreator.ts | 6 ------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/server/lib/BootProbes.ts b/app/server/lib/BootProbes.ts index adef4811..36c3786c 100644 --- a/app/server/lib/BootProbes.ts +++ b/app/server/lib/BootProbes.ts @@ -6,7 +6,7 @@ import { GristServer } from 'app/server/lib/GristServer'; import * as express from 'express'; import WS from 'ws'; import fetch from 'node-fetch'; -import { DEFAULT_SESSION_SECRET } from 'app/server/lib/coreCreator'; +import { DEFAULT_SESSION_SECRET } from 'app/server/lib/ICreate'; /** * Self-diagnostics useful when installing Grist. diff --git a/app/server/lib/ICreate.ts b/app/server/lib/ICreate.ts index 4b4d66ee..bf6fa69d 100644 --- a/app/server/lib/ICreate.ts +++ b/app/server/lib/ICreate.ts @@ -13,6 +13,9 @@ import {createSandbox, SpawnFn} from 'app/server/lib/NSandbox'; import {SqliteVariant} from 'app/server/lib/SqliteCommon'; import {ITelemetry} from 'app/server/lib/Telemetry'; +export const DEFAULT_SESSION_SECRET = + 'Phoo2ag1jaiz6Moo2Iese2xoaphahbai3oNg7diemohlah0ohtae9iengafieS2Hae7quungoCi9iaPh'; + export interface ICreate { Billing(dbManager: HomeDBManager, gristConfig: GristServer): IBilling; @@ -116,11 +119,7 @@ export function makeSimpleCreator(opts: { return createSandbox(opts.sandboxFlavor || 'unsandboxed', options); }, sessionSecret() { - const secret = process.env.GRIST_SESSION_SECRET || sessionSecret; - if (!secret) { - throw new Error('need GRIST_SESSION_SECRET'); - } - return secret; + return process.env.GRIST_SESSION_SECRET || sessionSecret || DEFAULT_SESSION_SECRET; }, async configure() { for (const s of storage || []) { diff --git a/app/server/lib/coreCreator.ts b/app/server/lib/coreCreator.ts index 477c970b..2eda4e9f 100644 --- a/app/server/lib/coreCreator.ts +++ b/app/server/lib/coreCreator.ts @@ -3,14 +3,8 @@ import { checkMinIOBucket, checkMinIOExternalStorage, import { makeSimpleCreator } from 'app/server/lib/ICreate'; import { Telemetry } from 'app/server/lib/Telemetry'; -export const DEFAULT_SESSION_SECRET = - 'Phoo2ag1jaiz6Moo2Iese2xoaphahbai3oNg7diemohlah0ohtae9iengafieS2Hae7quungoCi9iaPh'; - export const makeCoreCreator = () => makeSimpleCreator({ deploymentType: 'core', - // This can and should be overridden by GRIST_SESSION_SECRET - // (or generated randomly per install, like grist-omnibus does). - sessionSecret: DEFAULT_SESSION_SECRET, storage: [ { name: 'minio',