Skip to content

Instantly share code, notes, and snippets.

@NicholasLeader
Created August 9, 2019 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicholasLeader/6f47d61141ecfbd9de143a8447e525b6 to your computer and use it in GitHub Desktop.
Save NicholasLeader/6f47d61141ecfbd9de143a8447e525b6 to your computer and use it in GitHub Desktop.
###
# Nicholas Leader
# 8.9.2019
# Check for the presence of HTTP Security headers - CSP or Content-Security-Policy in this example
#
# Dictionary calling idea from: https://stackoverflow.com/questions/39090323/how-to-check-if-response-header-contains-certain-headers-powershell
#
###
### set Connection to use TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$URL_to_check = "https://securityheaders.com"
$HTTP_Header_to_check = "content-security-policy"
$response = Invoke-WebRequest $URL_to_check -UseBasicParsing
if ($response.Headers[$HTTP_Header_to_check] -ne $null) {
Write-Output "Found"
} else {
Write-Output "Not found"
}
# check website to see if headers are present / visable by script
# $response.headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment