fix: address review informational issues + add regression tests

- Add cookie-import to CHAIN_WRITE set for chain command routing
- Add path validation to snapshot -a -o output path
- Fix package.json version to match 0.3.1
- Use crypto.randomUUID() for temp DB paths (unpredictable filenames)
- Add regression tests for chain cookie-import and snapshot path validation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-12 20:59:21 -07:00
parent 47a8277567
commit d44bbe22ab
5 changed files with 43 additions and 3 deletions
+34
View File
@@ -1523,4 +1523,38 @@ describe('Path traversal prevention', () => {
expect(err.message).toContain('Path must be within');
}
});
test('snapshot -a -o rejects path outside safe dirs', async () => {
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
// First get a snapshot so refs exist
await handleMetaCommand('snapshot', ['-i'], bm, () => {});
try {
await handleMetaCommand('snapshot', ['-a', '-o', '/etc/evil.png'], bm, () => {});
expect(true).toBe(false);
} catch (err: any) {
expect(err.message).toContain('Path must be within');
}
});
});
// ─── Chain command: cookie-import in chain ──────────────────────
describe('Chain with cookie-import', () => {
test('cookie-import works inside chain', async () => {
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
const tmpCookies = '/tmp/test-chain-cookies.json';
fs.writeFileSync(tmpCookies, JSON.stringify([
{ name: 'chain_test', value: 'chain_value', domain: 'localhost', path: '/' }
]));
try {
const commands = JSON.stringify([
['cookie-import', tmpCookies],
]);
const result = await handleMetaCommand('chain', [commands], bm, async () => {});
expect(result).toContain('[cookie-import]');
expect(result).toContain('Loaded 1 cookie');
} finally {
try { fs.unlinkSync(tmpCookies); } catch {}
}
});
});