security: fix path validation bypass, CORS restriction, cookie-import path check

- startsWith('/tmp') matched '/tmpevil' — now requires trailing slash
- CORS Access-Control-Allow-Origin changed from * to http://127.0.0.1:<port>
- cookie-import now validates file paths (was missing validateReadPath)
- 3 new tests for prefix collision and cookie-import path traversal

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-12 20:49:34 -07:00
co-authored by Claude Opus 4.6
parent da7ec213e2
commit 47a8277567
5 changed files with 44 additions and 4 deletions
+28
View File
@@ -1495,4 +1495,32 @@ describe('Path traversal prevention', () => {
try { fs.unlinkSync(tmpFile); } catch {}
}
});
test('screenshot rejects /tmpevil prefix collision', async () => {
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
try {
await handleMetaCommand('screenshot', ['/tmpevil/steal.png'], bm, () => {});
expect(true).toBe(false);
} catch (err: any) {
expect(err.message).toContain('Path must be within');
}
});
test('cookie-import rejects path traversal', async () => {
try {
await handleWriteCommand('cookie-import', ['../../etc/shadow'], bm);
expect(true).toBe(false);
} catch (err: any) {
expect(err.message).toContain('Path traversal');
}
});
test('cookie-import rejects absolute path outside safe dirs', async () => {
try {
await handleWriteCommand('cookie-import', ['/etc/passwd'], bm);
expect(true).toBe(false);
} catch (err: any) {
expect(err.message).toContain('Path must be within');
}
});
});