Last active
May 14, 2019 08:30
-
-
Save p410n3/378c998293c47a789761e5f2c4594084 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch'); | |
const fs = require('fs'); | |
/* | |
* Reads a list of URLs from a file and return the CSP header if present | |
* Written by Phillip L - 14.15.2019 | |
*/ | |
const file = 'urls.csv'; | |
let csv = readCsv(file); | |
let domainArray = csv.split(','); | |
console.log('Sites with CSP Header set:'); | |
for (let domain of domainArray) { | |
logCspHeader(domain); | |
} | |
// HELPER HERE | |
function readCsv(filename) { | |
try { | |
let csv = fs.readFileSync(filename, { encoding: 'utf8' }).toString(); | |
return csv; | |
}catch (e) { | |
console.log('File not Found'); | |
process.exit(1); | |
} | |
} | |
function logCspHeader(domain) { | |
fetch(domain) | |
.then(response => response.headers.get('Content-Security-Policy')) | |
.then (csp => { | |
if (csp) { | |
console.log(domain); | |
} | |
}); | |
} | |
//Supress rejections for sites that are down | |
process.on('unhandledRejection', (err, p) => {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment