diff --git a/cloud/apps/sandbox-control/src/index.ts b/cloud/apps/sandbox-control/src/index.ts index 9640ce772b2..d77d71e7526 100644 --- a/cloud/apps/sandbox-control/src/index.ts +++ b/cloud/apps/sandbox-control/src/index.ts @@ -1241,6 +1241,15 @@ export function egressPlaceholderMode(value: string | undefined): boolean | Read * orca-git-identity hands an agent only that member's identity. Residual risk: members share the VM * user, so a member with a shell could subvert orcad itself; agents and prompts cannot. */ +/** + * The dev-only GitHub seed route (stores an installation token as a member's GitHub user token) exists only where + * SANDBOX_ENV is exactly one of the dev/test names: an allowlist, so unset, staging, prod or a typo all refuse + * (404, as if it weren't there). Operator token required on top. + */ +export function devSeedAllowed(env: Pick): boolean { + return env.SANDBOX_ENV === 'dev' || env.SANDBOX_ENV === 'local' || env.SANDBOX_ENV === 'test' +} + /** GIT-ACTOR (git-actor.ts): GH-AS-MEMBER on, and member git on for the account. */ function githubActingOptions(env: Env): GithubActingOptions { const memberGit = memberGitEnabled(env) @@ -1515,7 +1524,7 @@ async function routeRequest(request: Request, env: Env, deps: Deps): Promise { + it('is an allowlist: only dev, local and test', () => { + for (const env of ['dev', 'local', 'test']) { + expect(devSeedAllowed({ SANDBOX_ENV: env })).toBe(true) + } + for (const env of ['prod', 'staging', '', 'Dev', 'production', 'dev ', undefined as unknown as string]) { + expect(devSeedAllowed({ SANDBOX_ENV: env })).toBe(false) + } + }) + + it('answers 404 in staging and prod even with the operator token, and stores nothing', async () => { + for (const SANDBOX_ENV of ['staging', 'prod']) { + const h = await createHarness({ SANDBOX_ENV, OPERATOR_TOKEN: OP, SECRETS_KEK: Buffer.alloc(32, 7).toString('base64') }) + const seeded = await h.call('POST', '/v1/internal/dev/member-github', { + bearer: OP, + body: { accountId: 'org:acme', userId: 'alice', repoUrl: 'https://github.com/acme/app', login: 'alice-gh', githubUserId: 11, name: 'A' } + }) + expect(seeded.status).toBe(404) + expect(h.raw.prepare('SELECT COUNT(*) AS n FROM github_user_tokens').get()).toEqual({ n: 0 }) + } + }) +})