mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
fix(cloud): the dev GitHub seed route exists only where SANDBOX_ENV is dev, local or test (allowlist; was 'anything but prod')
This commit is contained in:
@@ -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<Env, 'SANDBOX_ENV'>): 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<Res
|
||||
if (url.pathname === '/v1/internal/github/app-webhook' && request.method === 'POST') {
|
||||
return await configureAppWebhook(env, deps, await readJson(request))
|
||||
}
|
||||
if (url.pathname === '/v1/internal/dev/member-github' && request.method === 'POST' && env.SANDBOX_ENV !== 'prod') {
|
||||
if (url.pathname === '/v1/internal/dev/member-github' && request.method === 'POST' && devSeedAllowed(env)) {
|
||||
// Dev rehearsal only: stand in a member's GitHub user token with a fresh app installation
|
||||
// token for one repo, so git-as-sender can be exercised without a second GitHub human.
|
||||
const body = DevMemberGitHubSchema.safeParse(await readJson(request))
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// The dev GitHub seed route stores any installation token as a member's GitHub user token: it must not exist
|
||||
// outside dev/local/test, whatever else is configured.
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { devSeedAllowed } from '../src/index'
|
||||
import { createHarness } from './harness'
|
||||
|
||||
const OP = 'o'.repeat(40)
|
||||
|
||||
describe('dev member-github seed route gate', () => {
|
||||
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 })
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user