- test(e2e): add playwright harness and test stack - test(e2e): add core flow - fix(ui): preserve same-origin browser form submissions - fix(ui): offer reload inside stale edit dialogs - test(e2e): add persona session and accessibility suites - test(e2e): preserve per-run artifacts and clean pulled images - test(e2e): verify import and audit state across navigation - test(e2e): tighten verification helpers and persona checks - test(e2e): bound response body reads of the browser observer - test: recover review compatibility assertions - test: stabilize audit and user flow assertions
84 lines
3.5 KiB
JavaScript
84 lines
3.5 KiB
JavaScript
// 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 `<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head><meta charset="utf-8"><title>Second origin</title></head>
|
|
<body>
|
|
<h1>Second origin</h1>
|
|
<pre id="results"></pre>
|
|
<form id="logout" method="post" action="${safeTarget}/logout"></form>
|
|
<form id="login" method="post" action="${safeTarget}/login">
|
|
<input name="username" value="attacker"><input name="password" value="attacker-password-1"><input name="next" value="/">
|
|
</form>
|
|
<script src="/attack.js"></script>
|
|
</body>
|
|
</html>`;
|
|
}
|
|
|
|
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)));
|
|
}
|