Answer a test's HTTPS request without echoing it back.

CodeQL alert #583 (js/reflected-xss): tests/httpsServer.test.cjs's server
answered `served ${req.url} ...`, sending the request back as the body. It
now names the page by comparison, as plain text.
tests/noReflectedRequest.test.cjs keeps the shape out of every file: no
res.end/res.write/res.send writes a request's url, query, params, headers or
body into the response. Test code only, so nothing for Admin Panel / Problems
to record.

Thanks to GitHub CodeQL and xet7 !
This commit is contained in:
Lauri Ojansivu committed 2026-10-14 11:05:15 +03:00
1 parent b8a6fc371b
commit 73fcfb8545
2 files changed
+57 -1

No files matched your search

+8 -1
View File
@@ -51,7 +51,14 @@ test('the redirect keeps only the path, and names a host the browser asked for o
test('pages and websocket upgrades over TLS, through the existing HTTP server; a renewed certificate without a restart', { skip: !HAS_OPENSSL && 'needs openssl' }, async () => {
const dir = fs.mkdtempSync(path.join(ROOT, '.tools', 'tmp', 'https-'));
const first = selfSigned(dir, 'first.example');
const app = http.createServer((req, res) => res.end(`served ${req.url} encrypted=${!!req.socket.encrypted}`));
// The page is named by comparison, never by echoing req.url back: a
// response that reflects the request is the reflected-XSS shape (CodeQL
// #583), even in a test (tests/noReflectedRequest.test.cjs).
const app = http.createServer((req, res) => {
const page = req.url === '/hello' ? '/hello' : 'another page';
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.end(`served ${page} encrypted=${!!req.socket.encrypted}`);
});
let upgraded = false;
app.on('upgrade', (req, socket) => { upgraded = true; socket.end('HTTP/1.1 101 Switching Protocols\r\n\r\n'); });
const env = { HTTPS_PORT: '1', HTTPS_CERT_FILE: first.cert, HTTPS_KEY_FILE: first.key };