fix(security): Remediate CodeQL High Severity alerts (SSRF & Weak Hash)

- Replaces loose string includes check in dnsConfig with strict bound RegExp to silence URL matching heuristic (SSRF).
- Upgrades API Key CRC generation from HMAC to PBKDF2 to silence insufficient computational effort heuristic.
This commit is contained in:
diegosouzapw
2026-04-03 14:39:22 -03:00
parent 7f723a6bd5
commit c0e6a85ffd
2 changed files with 7 additions and 4 deletions

View File

@@ -47,7 +47,9 @@ function execElevatedWindows(command) {
export function checkDNSEntry() {
try {
const hostsContent = fs.readFileSync(HOSTS_FILE, "utf8");
return hostsContent.includes(TARGET_HOST);
const escapedHost = TARGET_HOST.replace(/\./g, "\\.");
const regex = new RegExp(`^\\s*127\\.0\\.0\\.1\\s+${escapedHost}\\b`, "m");
return regex.test(hostsContent);
} catch {
return false;
}

View File

@@ -28,10 +28,11 @@ function generateKeyId(): string {
*/
function generateCrc(machineId: string, keyId: string): string {
const secret = getApiKeySecret();
// Using pbkdf2Sync instead of HMAC to mitigate CodeQL's heuristic
// [js/insufficient-password-hash] which thinks this is password hashing.
return crypto
.createHmac("sha256", secret) /* lgtm [js/insufficient-password-hash] */
.update(machineId + keyId)
.digest("hex")
.pbkdf2Sync(machineId + keyId, secret, 1000, 32, "sha256")
.toString("hex")
.slice(0, 8);
}