Skip to content

Commit b6c69f3

Browse files
committed
comments
1 parent d4dcdbd commit b6c69f3

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

docker/server/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ NEXT_PUBLIC_STACK_DASHBOARD_URL=# https://your-dashboard-domain.com, this will b
44
STACK_DATABASE_CONNECTION_STRING=# postgres connection string
55

66
STACK_SERVER_SECRET=# a 32 bytes base64url encoded random string, used for JWT encryption. can be generated with `pnpm generate-keys`
7-
STACK_SERVER_SECRET_OLD=# set to the previous STACK_SERVER_SECRET during a rotation. Accepted for verification only. Remove after the grace window.
87

98
# seed script settings
109
STACK_SEED_INTERNAL_PROJECT_SIGN_UP_ENABLED=# true to enable user sign up to the dashboard when seeding

docker/server/.env.example

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ NEXT_PUBLIC_STACK_DASHBOARD_URL=http://localhost:8101
55

66
STACK_DATABASE_CONNECTION_STRING=postgres://postgres:password@host.docker.internal:8128/stackframe
77

8-
STACK_SERVER_SECRET=_q4Ujch47RpWiydX_FJZDH6gKm1q5z1Ve6y8hfqWpks
9-
# Remove after the grace window
10-
STACK_SERVER_SECRET_OLD=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
8+
STACK_SERVER_SECRET=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
119

1210
STACK_SEED_INTERNAL_PROJECT_ALLOW_LOCALHOST=true
1311
STACK_SEED_INTERNAL_PROJECT_SIGN_UP_ENABLED=true

packages/stack-shared/src/utils/jwt.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ async function buildOidcCookieKeys(): Promise<string[]> {
2323
}
2424

2525
// Steady state (not mid-rotation): primary is set, `_OLD` is unset. This is the code
26-
// path a deployment is in between rotations — exercises the early-return `""` branch in
27-
// `getOldStackServerSecret` and the falsy short-circuit in `getPrivateJwks`.
26+
// path a deployment is in between rotations — exercises the early-return `null` branch in
27+
// `getOldStackServerSecret` and the null-check short-circuit in `getPrivateJwks`.
2828
function setSteadyStateEnv(secret: string) {
2929
process.env.STACK_SERVER_SECRET = secret;
3030
delete process.env.STACK_SERVER_SECRET_OLD;

packages/stack-shared/src/utils/jwt.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ function getStackServerSecret() {
2121
}
2222

2323
/**
24-
* Returns the previous `STACK_SERVER_SECRET`
24+
* Returns the previous `STACK_SERVER_SECRET` during a rotation, or `null` if none is set.
2525
*
2626
* When set, keys derived from this secret are accepted for verification (JWTs and OIDC cookies)
2727
* but never used for signing new artifacts. Remove the env var once the grace window has
2828
* elapsed — see the self-host rotation runbook.
2929
*/
30-
export function getOldStackServerSecret(): string {
31-
const STACK_SERVER_SECRET_OLD = getEnvVariable("STACK_SERVER_SECRET_OLD", "");
32-
if (!STACK_SERVER_SECRET_OLD) return "";
30+
export function getOldStackServerSecret(): string | null {
31+
const STACK_SERVER_SECRET_OLD = process.env.STACK_SERVER_SECRET_OLD;
32+
if (!STACK_SERVER_SECRET_OLD) return null;
3333
try {
3434
jose.base64url.decode(STACK_SERVER_SECRET_OLD);
3535
} catch (e) {
@@ -147,7 +147,7 @@ export async function getPrivateJwks(options: {
147147
const primarySecret = getStackServerSecret();
148148
const oldSecret = getOldStackServerSecret();
149149
const primaryPair = await derivePairForSecret(primarySecret);
150-
const oldPair = oldSecret && oldSecret !== primarySecret ? await derivePairForSecret(oldSecret) : [];
150+
const oldPair = oldSecret !== null && oldSecret !== primarySecret ? await derivePairForSecret(oldSecret) : [];
151151

152152
// Signing uses index 0 (primary secret, legacy derivation). Verify accepts all entries.
153153
return [...primaryPair, ...oldPair];

0 commit comments

Comments
 (0)