// scripts/verify-svg-logo-security.js // Comprehensive security verification suite for SVG Brand Logos in ADPanel Enterprise. // Verifies neutralization of all known SVG attack vectors and confirms defense-in-depth guarantees. "use strict"; const assert = require("assert"); const branding = require("../utils/branding.js"); const { sanitizeSvg, validateSvgBuffer, ALLOWED_TAGS, DANGEROUS_BLOCK_TAGS } = require("../utils/svg-sanitizer.js"); let checks = 0; function ok(name, cond) { assert.ok(cond, `FAILED: ${name}`); checks += 1; console.log(` [PASS] ${name}`); } console.log("==============================================================================="); console.log("RUNNING ENTERPRISE SVG LOGO SECURITY VERIFICATION SUITE"); console.log("===============================================================================\n"); // ----------------------------------------------------------------------------- // TEST SUITE 1: Direct Script Injection Neutralization // ----------------------------------------------------------------------------- console.log("--- TEST SUITE 1: Script Injection Neutralization ---"); { const rawSvg = ` `; const res = sanitizeSvg(rawSvg); ok("Sanitizer accepts valid SVG structure", res.valid === true); const out = res.sanitized.toString("utf8"); ok("Direct `; const res = sanitizeSvg(rawSvg); ok("SVG with foreignObject processed", res.valid === true); const out = res.sanitized.toString("utf8"); ok(" stripped", !out.includes(" stripped", !out.includes(" stripped", !out.includes(" stripped", !out.includes("foreignObject-xss")); ok("Safe sibling element preserved", out.includes(" `; const res = sanitizeSvg(rawSvg); ok("Link/pseudo-protocol vectors processed", res.valid === true); const out = res.sanitized.toString("utf8"); ok(" tags stripped/disallowed in brand logo", !out.includes("")); ok("javascript: pseudo-protocol completely absent", !out.includes("javascript:")); ok("data:text/html completely absent", !out.includes("data:text/html")); } // ----------------------------------------------------------------------------- // TEST SUITE 6: XXE (XML External Entity) & Billion Laughs Rejection // ----------------------------------------------------------------------------- console.log("\n--- TEST SUITE 6: XXE & Denial of Service Bombs ---"); { const xxePayload = ` ]> &xxe; `; const res = sanitizeSvg(xxePayload); ok("XXE with strictly rejected", res.valid === false); ok("Error explicitly mentions XXE violation", /xxe|entity/i.test(res.error || "")); } { const billionLaughs = ` ]> &lol2; `; const res = sanitizeSvg(billionLaughs); ok("Billion Laughs XML bomb strictly rejected", res.valid === false); } { const nullBytePayload = Buffer.from(""); const res = sanitizeSvg(nullBytePayload); ok("Null byte injection strictly rejected", res.valid === false); ok("Error mentions null bytes", /null byte/i.test(res.error || "")); } // ----------------------------------------------------------------------------- // TEST SUITE 7: and External Smuggling Protection // ----------------------------------------------------------------------------- console.log("\n--- TEST SUITE 7: and Resource Protection ---"); { const rawSvg = ` `; const res = sanitizeSvg(rawSvg); ok("Use and image tags processed", res.valid === true); const out = res.sanitized.toString("utf8"); ok("Local preserved", out.includes('href="#my-circle"')); ok("External stripped", !out.includes("attacker.com")); ok("javascript: in stripped", !out.includes("javascript:alert")); ok("Safe base64 raster preserved", out.includes('image/png;base64')); ok("data:text/html in stripped", !out.includes("data:text/html")); } // ----------------------------------------------------------------------------- // TEST SUITE 8: CSS &