// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 2026 Bryan Joshua Pedini import http from 'node:http'; const port = Number(process.env.ORIGIN2_PORT || 8081); const hits = []; const attackScript = ` const params = new URLSearchParams(location.search); const target = params.get('target'); const results = {}; async function probe(name, url, init) { try { const res = await fetch(url, init); results[name] = { type: res.type, status: res.status }; } catch (err) { results[name] = { error: String(err && err.message ? err.message : err) }; } } async function main() { await probe('create_zone_simple', target + '/api/v1/zones', { method: 'POST', mode: 'no-cors', credentials: 'include', headers: { 'Content-Type': 'text/plain' }, body: JSON.stringify({ name: params.get('zone'), ns: 'ns1.' + params.get('zone'), mbox: 'hostmaster@' + params.get('zone'), extra_ns: [], refresh: 3600, retry: 600, expire: 604800, minttl: 300, ttl: 3600 }) }); await probe('create_zone_cors', target + '/api/v1/zones', { method: 'POST', mode: 'cors', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: params.get('zone') }) }); await probe('read_zones', target + '/api/v1/zones', { method: 'GET', mode: 'cors', credentials: 'include' }); await probe('delete_user', target + '/api/v1/users/' + encodeURIComponent(params.get('victim') || 'nobody'), { method: 'DELETE', mode: 'no-cors', credentials: 'include', headers: { 'Content-Type': 'text/plain' }, body: JSON.stringify({ confirm: params.get('victim') }) }); document.getElementById('results').textContent = JSON.stringify(results); document.body.dataset.done = '1'; if (params.get('form') === 'logout') document.getElementById('logout').submit(); } main(); `; function attackPage(query) { const target = new URLSearchParams(query).get('target') || ''; const safeTarget = /^http:\/\/[a-z0-9-]+:[0-9]+$/.test(target) ? target : 'http://invalid.invalid'; return ` Second origin

Second origin


`; } const server = http.createServer((req, res) => { const url = new URL(req.url, `http://${req.headers.host || 'origin2'}`); hits.push({ method: req.method, path: url.pathname, at: new Date().toISOString() }); if (hits.length > 500) hits.shift(); if (url.pathname === '/health') { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end('{"status":"ok"}'); return; } if (url.pathname === '/attack.js') { res.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'no-store' }); res.end(attackScript); return; } if (url.pathname === '/attack.html') { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' }); res.end(attackPage(url.search)); return; } if (url.pathname === '/hits') { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(hits)); return; } res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('not found'); }); server.listen(port, '0.0.0.0'); for (const signal of ['SIGINT', 'SIGTERM']) { process.on(signal, () => server.close(() => process.exit(0))); }