mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(sandbox): harden enforcement validation and backup handling
This commit is contained in:
1 parent
f315dda3f3
commit
0481160f5e
13 files changed
+180
-101
No files matched your search
@@ -416,11 +416,12 @@ describe('opencode plugin quarantine', () => {
|
||||
expect(backup.sanitizedConfig).toEqual({ model: 'x' })
|
||||
})
|
||||
|
||||
it('strips local MCP servers and the formatter while keeping remote MCP servers', async () => {
|
||||
it('strips every MCP server that is not provably remote along with the formatter', async () => {
|
||||
writeConfig({
|
||||
mcp: {
|
||||
local: { type: 'local', command: ['npx', 'evil-server'] },
|
||||
shorthand: { command: ['node', 'server.js'] },
|
||||
stringCommand: { command: 'node server.js' },
|
||||
remote: { type: 'remote', url: 'https://example.com/mcp' },
|
||||
toggled: { enabled: false },
|
||||
},
|
||||
@@ -433,7 +434,6 @@ describe('opencode plugin quarantine', () => {
|
||||
const sanitized = JSON.parse(await fs.readFile(configPath, 'utf-8')) as Record<string, unknown>
|
||||
expect(sanitized.mcp).toEqual({
|
||||
remote: { type: 'remote', url: 'https://example.com/mcp' },
|
||||
toggled: { enabled: false },
|
||||
})
|
||||
expect(sanitized.formatter).toBeUndefined()
|
||||
expect(sanitized.model).toBe('x')
|
||||
@@ -444,6 +444,8 @@ describe('opencode plugin quarantine', () => {
|
||||
mcp: {
|
||||
local: { type: 'local', command: ['npx', 'evil-server'] },
|
||||
shorthand: { command: ['node', 'server.js'] },
|
||||
stringCommand: { command: 'node server.js' },
|
||||
toggled: { enabled: false },
|
||||
},
|
||||
formatter: { typescript: { command: ['prettier', '--write'] } },
|
||||
})
|
||||
@@ -513,6 +515,22 @@ describe('opencode plugin quarantine', () => {
|
||||
await expect(fs.access(`${configPath}.ocm-sandbox-backup`)).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('refuses to overwrite a corrupt backup so the sections it holds are never lost', async () => {
|
||||
writeConfig({
|
||||
mcp: { local: { type: 'local', command: ['npx', 'evil-server'] } },
|
||||
formatter: { typescript: { command: ['prettier'] } },
|
||||
model: 'x',
|
||||
})
|
||||
await quarantineOpenCodePlugins(configHome, configPath)
|
||||
|
||||
const backupPath = `${configPath}.ocm-sandbox-backup`
|
||||
const corrupt = '{ "removedSections": '
|
||||
writeFileSync(backupPath, corrupt)
|
||||
|
||||
await expect(quarantineOpenCodePlugins(configHome, configPath)).rejects.toThrow(/refusing to overwrite it/)
|
||||
expect(await fs.readFile(backupPath, 'utf-8')).toBe(corrupt)
|
||||
})
|
||||
|
||||
it('replaces a quarantined section with a newly supplied prohibited value while preserving other backed-up sections', async () => {
|
||||
writeConfig({
|
||||
mcp: { local: { type: 'local', command: ['npx', 'old-server'] } },
|
||||
|
||||
Reference in new issue
Block a user