Skip to content

Commit 16c0f43

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
fix(webapp): seal public token subjects with their own secret
Add PUBLIC_TOKEN_SUBJECT_SECRET, a dedicated key for the encrypted environment id in public access tokens. When it is unset the webapp keeps using ENCRYPTION_KEY, so self-hosted instances need no change. Mono-RevId: 18984b40421bf99ba9a0f7201ea1e89076de1efb
1 parent 9aa4d99 commit 16c0f43

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎apps/webapp/app/env.server.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ const EnvironmentSchema = z
417417
)
418418
.refine(isNotInsecureSecret, INSECURE_SECRET_MESSAGE),
419419
PUBLIC_TOKEN_SEALED_SUBJECT_ENABLED: BoolEnv.default(false),
420+
PUBLIC_TOKEN_SUBJECT_SECRET: z
421+
.string()
422+
.min(32)
423+
.refine(isNotInsecureSecret, INSECURE_SECRET_MESSAGE)
424+
.optional(),
420425
// Enables the AWS_KMS secret store provider. Callers opt in per secret; everything else
421426
// stays encrypted with ENCRYPTION_KEY.
422427
SECRET_STORE_AWS_KMS_KEY_ID: z.string().optional(),
@@ -2879,9 +2884,10 @@ if (env.ALLOW_INSECURE_DEFAULT_SECRETS) {
28792884
["MAGIC_LINK_SECRET", env.MAGIC_LINK_SECRET],
28802885
["ENCRYPTION_KEY", env.ENCRYPTION_KEY],
28812886
["MANAGED_WORKER_SECRET", env.MANAGED_WORKER_SECRET],
2887+
["PUBLIC_TOKEN_SUBJECT_SECRET", env.PUBLIC_TOKEN_SUBJECT_SECRET],
28822888
] as const
28832889
)
2884-
.filter(([, value]) => INSECURE_SECRET_VALUES.includes(value))
2890+
.filter(([, value]) => value !== undefined && INSECURE_SECRET_VALUES.includes(value))
28852891
.map(([name]) => name);
28862892

28872893
if (insecure.length > 0) {

‎apps/webapp/app/services/publicTokenSubject.server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { env } from "~/env.server";
44
let codec: PublicTokenSubjectCodec | undefined;
55

66
function getCodec(): PublicTokenSubjectCodec {
7-
codec ??= createPublicTokenSubjectCodec(env.ENCRYPTION_KEY);
7+
codec ??= createPublicTokenSubjectCodec(env.PUBLIC_TOKEN_SUBJECT_SECRET ?? env.ENCRYPTION_KEY);
88
return codec;
99
}
1010

‎docs/self-hosting/env/webapp.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ mode: "wide"
1212
| `MAGIC_LINK_SECRET` | Yes | — | Magic link encryption secret. Run: `openssl rand -hex 16` |
1313
| `ENCRYPTION_KEY` | Yes | — | Secret store encryption key. Run: `openssl rand -hex 16` |
1414
| `MANAGED_WORKER_SECRET` | Yes | — | Managed worker secret. Must be set and match supervisor. Run: `openssl rand -hex 32` |
15+
| `PUBLIC_TOKEN_SUBJECT_SECRET` | No | `ENCRYPTION_KEY` | Key that encrypts the environment id inside public access tokens. Set it to keep this separate from the secret store key. Run: `openssl rand -hex 32` |
16+
| `PUBLIC_TOKEN_SEALED_SUBJECT_ENABLED` | No | false | Encrypt the environment id inside newly minted public access tokens. Turn on only once every webapp instance runs a version that can read them. |
1517
| `ALLOW_INSECURE_DEFAULT_SECRETS` | No | false | Boot even if a secret is still a known-insecure published default. Temporary escape hatch for values you can't safely rotate yet (see [Secrets](/self-hosting/kubernetes#secrets)). |
1618
| **Domains & ports** | | | |
1719
| `REMIX_APP_PORT` | No | 3030 | Remix app port. |

0 commit comments

Comments
 (0)