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
3 changes: 3 additions & 0 deletions src/sandbox/sandbox-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,9 @@ export const SandboxRuntimeConfigSchema = z
'`safe.directory` without adding them to `filesystem.allowWrite`.',
),
})
// Reject unknown top-level keys so misspelled policy settings fail closed
// instead of being silently stripped by Zod.
.strict()
.superRefine((cfg, ctx) => {
const creds = cfg.credentials
if (!creds) return
Expand Down
27 changes: 27 additions & 0 deletions test/config-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ describe('Config Validation', () => {
expect(result.success).toBe(true)
})

test('should reject unknown top-level config keys', () => {
const result = SandboxRuntimeConfigSchema.safeParse({
network: {
allowedDomains: [],
deniedDomains: [],
},
filesystem: {
denyRead: [],
allowWrite: [],
denyWrite: [],
},
denyWriteTypo: ['/Users/me'],
})

expect(result.success).toBe(false)
if (!result.success) {
expect(
result.error.issues.some(
issue =>
issue.code === 'unrecognized_keys' &&
issue.path.length === 0 &&
issue.keys.includes('denyWriteTypo'),
),
).toBe(true)
}
})

test('should validate a config with valid domains', () => {
const config = {
network: {
Expand Down