clawdie-ai/scripts/browser-jail-clone-validation/cookie-server.mjs
Operator & Codex 3ea26f231d Validate browser clone cookie injection
---
Build: pass | Tests: pass — 2383 passed (175 files)
2026-05-11 16:19:12 +02:00

28 lines
1.1 KiB
JavaScript

import http from 'node:http';
const host = process.env.COOKIE_SERVER_HOST ?? '127.0.0.1';
const port = Number(process.env.COOKIE_SERVER_PORT ?? '18080');
const cookieName = process.env.COOKIE_NAME ?? 'phase06_cookie';
const cookieValue = process.env.COOKIE_VALUE ?? 'roundtrip-ok';
const server = http.createServer((req, res) => {
const url = new URL(req.url ?? '/', `http://${host}:${port}`);
if (url.pathname === '/set') {
res.setHeader('Set-Cookie', `${cookieName}=${cookieValue}; Path=/; SameSite=Lax`);
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ ok: true, action: 'set', cookieName, cookieValue }));
return;
}
if (url.pathname === '/echo') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ ok: true, cookie: req.headers.cookie ?? '' }));
return;
}
res.statusCode = 404;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ ok: false, error: 'not found' }));
});
server.listen(port, host, () => {
console.log(JSON.stringify({ ok: true, listening: `http://${host}:${port}` }));
});