The script (and burp plugin) validates whether the headers pertaining to security are present and if present, whether they have been configured securely. It implements checks identified by
- https://securityheaders.io/
- https://csp.withgoogle.com
- OWASPs cheat sheets
- Original research
- Security Headers Checker
- TL; DR
- Table of Contents
- Introduction
- Installation and Execution
- Security Headers
- References
- Clear-Site-Data References
- Content-Security-Policy References
- CORS References
- Feature-Policy References
- HPKP References
- HTTP-Strict-Transport-Security (HSTS) References
- Referrer-Policy References
- X-Frame-Options (XFO) References
- X-Content-Type-Options References
- X-Download-Options References
- X-Permitted-Cross-Domain-Policies References
- X-XSS-Protection References
- TODOs
Applications can set secure HTTP response headers as an additional layer of defense that prevents browsers from running into easy preventable vulnerabilities. The script in this repository validates whether the headers pertaining to security are present and if present, whether they have been configured securely. In summary, the script implements the checks identified by
- https://securityheaders.io/
- https://csp.withgoogle.com
- original research
Make sure you have Python 2 or Python 3 installed. The current limitation of Python 3 is that the 'ScriptSrc'-style tags of the Content-Security-Policy are not analyzed.
Install the dependencies:
pip install -r requirements.txtStart the script as follows.
python securityheaders.py URIUse the -h flag for all options.
python securityheaders.py -hIn the example below, we execute the script to validate the headers of google.com.
python securityheaders.py google.comBy default the script will display all the response headers it received from the server. To not display those, execute the --skipheaders flag with the InfoCollector value.
python securityheaders.py google.com --skipcheckers InfoCollectorThe script also shows if security headers are missing. To disable those checks, add HeaderMissingChecker to the --skipheaders flag.
python securityheaders.py google.com --skipcheckers InfoCollector HeaderMissingCheckerThe script can show a list of supported checkers via the --listcheckers flag.
python securityheaders.py --listcheckersBy default the script executes all of the listed checkers. Disable checkers with the --skipcheckers flag or execute specific checkers with the --checkers flag. If a checker has children, then the script skips or executes all the children checkers. In the example below, the script executes all checkers that find Content Security Policy issues, but skips the checkers that fire when the CSP header is missing.
python securityheaders.py https://scotthelme.co.uk --checkers CSPChecker --skipcheckers HeaderMissingCheckerBy default the script shows the output in a tabular format. To create output in a different format, use the --formatter flag. In the example below, the script outputs the findings as CSV. Note that formatters base64-encode the fields that may contain control characters for that format. For instance, for CSV the description is base 64 encoded as it may contain commas.
python securityheaders.py https://scotthelme.co.uk --formatter csvpython securityheaders.py --listformattersTo write output to a file rather displaying it on the screen, use the --file flag.
python securityheaders.py https://scotthelme.co.uk --file ./tmpTo check multiple websites, separate them with a comma.
python securityheaders.py https://scotthelme.co.uk,https://google.com --skipcheckers InfoCollector HeaderMissingCheckerTo merge output into one table, use the --flatten flag. Avoid this if you are checking many (500k+) websites, as you may run out of memory.
python securityheaders.py https://scotthelme.co.uk,https://google.com --flatten --skipcheckers InfoCollector HeaderMissingCheckerTo load URLs from a file, use a filename rather than a URL.
python securityheaders.py top10.txt --flattenIf the file is a CSV file, tell the column with URLs with the --urlcolumn flag (zero-indexed). To skip the CSV header row, use the --startrow flag.
python securityheaders.py majestic_10.csv --startrow 2 --urlcolumn 2To analyze a saved response, use the --response rather than a URL.
python securityheaders.py --response google.txtBy passing a single dash (-) to --response the file will be read from sys.stdin
python securityheaders.py --response - HTTP/1.1 200 OK Date: Sun, 14 Oct 2018 12:59:11 GMT Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop [TRUNCATED]













