Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sandbox/sandbox-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,10 @@ export const SandboxRuntimeConfigSchema = z
'`safe.directory` without adding them to `filesystem.allowWrite`.',
),
})
// Reject unknown top-level keys so a typo like `denyWriteTypo` fails
// loudly instead of being silently stripped while the operator believes
// the policy is enforced. Same reasoning as the strict sub-schemas above.
.strict()
.superRefine((cfg, ctx) => {
const creds = cfg.credentials
if (!creds) return
Expand Down
55 changes: 42 additions & 13 deletions test/config-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { describe, test, expect } from 'bun:test'
import { SandboxRuntimeConfigSchema } from '../src/sandbox/sandbox-config.js'

describe('Config Validation', () => {
test('should validate a valid minimal config', () => {
const config = {
network: {
allowedDomains: [],
deniedDomains: [],
},
filesystem: {
denyRead: [],
allowWrite: [],
denyWrite: [],
},
}
const validConfig = {
network: {
allowedDomains: [],
deniedDomains: [],
},
filesystem: {
denyRead: [],
allowWrite: [],
denyWrite: [],
},
}

const result = SandboxRuntimeConfigSchema.safeParse(config)
test('should validate a valid minimal config', () => {
const result = SandboxRuntimeConfigSchema.safeParse(validConfig)
expect(result.success).toBe(true)
})

Expand Down Expand Up @@ -127,6 +127,35 @@ describe('Config Validation', () => {
expect(result.success).toBe(false)
})

test('should reject unknown top-level keys', () => {
// A typo like `denyWriteTypo` must fail loudly instead of being
// silently stripped while the operator believes the policy is
// enforced (issue #434).
const config = {
...validConfig,
denyWriteTypo: ['/Users/me'],
}

const result = SandboxRuntimeConfigSchema.safeParse(config)
expect(result.success).toBe(false)
if (!result.success) {
const messages = result.error.issues.map(issue => issue.message)
expect(messages.some(message => message.includes('denyWriteTypo'))).toBe(
true,
)
}
})

test('should still reject unknown top-level keys alongside valid config', () => {
const config = {
...validConfig,
allowEverything: true,
}

const result = SandboxRuntimeConfigSchema.safeParse(config)
expect(result.success).toBe(false)
})

test('should validate wildcard domains correctly', () => {
const validWildcards = ['*.example.com', '*.github.io', '*.co.uk']

Expand Down