Added draft for CSP health checker

This commit is contained in:
2025-05-13 09:10:20 +02:00
parent 72baa9ea28
commit 23496f2fab
18 changed files with 424 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
const puppeteer = require('puppeteer');
const domains = process.argv.slice(2);
(async () => {
let errorCounter = 0;
const browser = await puppeteer.launch({ headless: 'new' });
for (const domain of domains) {
const page = await browser.newPage();
const blockedResources = [];
page.on('requestfailed', request => {
const reason = request.failure()?.errorText || '';
if (reason.includes('blocked')) {
blockedResources.push({ url: request.url(), reason });
}
});
try {
const url = `https://${domain}`;
await page.goto(url, { waitUntil: 'networkidle2', timeout: 20000 });
} catch (e) {
console.error(`${domain}: ERROR visiting site - ${e.message}`);
errorCounter++;
continue;
}
if (blockedResources.length > 0) {
console.warn(`${domain}: Blocked resources detected:`);
blockedResources.forEach(r =>
console.log(` BLOCKED by CSP: ${r.url} (${r.reason})`)
);
errorCounter++;
} else {
console.log(`${domain}: ✅ No CSP blocks detected.`);
}
await page.close();
}
await browser.close();
process.exit(errorCounter);
})();