Fix results returned by CodeQL scan

This commit is contained in:
Alicia Sykes committed 2025-10-14 19:20:55 +01:00
1 parent 3f59d7743d
commit 0d98397000
4 files changed
+19 -5

No files matched your search

@@ -1,12 +1,12 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { exec } from 'child_process';
import { execFile } from 'child_process';
import { promisify } from 'util';
import { promises as dns } from 'dns';
export const config = { runtime: 'nodejs22.x' };
const execAsync = promisify(exec);
const execFileAsync = promisify(execFile);
interface AXFRRequest {
domain: string;
@@ -48,7 +48,7 @@ async function checkDigAvailable(): Promise<boolean> {
if (digAvailable !== null) return digAvailable;
try {
await execAsync('dig -v', { timeout: 2000 });
await execFileAsync('dig', ['-v'], { timeout: 2000 });
digAvailable = true;
return true;
} catch {
@@ -93,10 +93,11 @@ async function testAXFR(domain: string, nameserver: string, ip: string): Promise
try {
// Use dig for AXFR query with timeout
const command = `dig @${ip} ${domain} AXFR +time=5 +retry=1 +noidnout 2>&1`;
// Using execFile instead of exec to prevent command injection
const args = [`@${ip}`, domain, 'AXFR', '+time=5', '+retry=1', '+noidnout'];
const { stdout, stderr } = await Promise.race([
execAsync(command, { maxBuffer: 1024 * 1024 * 5 }), // 5MB max
execFileAsync('dig', args, { maxBuffer: 1024 * 1024 * 5 }), // 5MB max
new Promise<never>((_, reject) => setTimeout(() => reject(new Error('AXFR query timeout')), AXFR_TIMEOUT_MS)),
]);
@@ -71,6 +71,8 @@ async function checkSTARTTLS(domain: string, port: number): Promise<Partial<TLSC
tlsSocket = (tls as any).connect({
socket,
servername: domain,
// SECURITY: rejectUnauthorized must be false for this mail TLS diagnostic tool.
// This tool analyzes mail server certificates including those with issues.
rejectUnauthorized: false,
});
@@ -127,6 +129,8 @@ async function checkDirectTLS(domain: string, port: number): Promise<Partial<TLS
host: domain,
port,
servername: domain,
// SECURITY: rejectUnauthorized must be false for this mail TLS diagnostic tool.
// This tool analyzes mail server certificates including those with issues.
rejectUnauthorized: false,
timeout: 5000,
});
@@ -101,6 +101,8 @@ function performTLSHandshake(hostname: string, port: number): Promise<TLSHandsha
{
socket: tcpSocket,
servername: hostname,
// SECURITY: rejectUnauthorized must be false for this TLS diagnostic tool.
// This tool analyzes TLS handshakes including servers with certificate issues.
rejectUnauthorized: false,
ALPNProtocols: ['h2', 'http/1.1'],
},
@@ -106,6 +106,9 @@ async function getCertificateInfo(host: string, port: number, servername?: strin
host,
port,
servername: servername || host,
// SECURITY: rejectUnauthorized must be false for this diagnostic tool to work.
// This is a TLS analysis tool that needs to inspect certificates from servers with
// self-signed, expired, or misconfigured certificates. This is intentional and safe.
rejectUnauthorized: false,
timeout: 10000,
};
@@ -194,6 +197,7 @@ async function probeTLSVersions(host: string, port: number, servername?: string)
servername: servername || host,
minVersion: version,
maxVersion: version,
// SECURITY: rejectUnauthorized must be false to test TLS version support (see above)
rejectUnauthorized: false,
timeout: 5000,
};
@@ -251,6 +255,7 @@ async function probeALPN(host: string, port: number, protocols: string[], server
port,
servername: servername || host,
ALPNProtocols: protocols,
// SECURITY: rejectUnauthorized must be false to test ALPN negotiation (see above)
rejectUnauthorized: false,
timeout: 10000,
};
@@ -313,6 +318,7 @@ async function checkOCSPStapling(hostname: string, port: number = 443): Promise<
port,
servername: hostname,
requestOCSP: true,
// SECURITY: rejectUnauthorized must be false to test OCSP stapling (see above)
rejectUnauthorized: false,
};
@@ -389,6 +395,7 @@ async function testCipherPresets(hostname: string, port: number = 443): Promise<
{
host: hostname,
port,
// SECURITY: rejectUnauthorized must be false to test cipher presets (see above)
rejectUnauthorized: false,
},
() => {