Skip to content

Instantly share code, notes, and snippets.

@mcls
Created June 11, 2018 11:22
Show Gist options
  • Save mcls/8375c19f4b413da629558825955beefd to your computer and use it in GitHub Desktop.
Save mcls/8375c19f4b413da629558825955beefd to your computer and use it in GitHub Desktop.
CORS headers checking script
#!/usr/bin/env bash
#
# Minimimal example:
#
# cors_headers https://www.google.com
#
# Example with origin (-o):
#
# cors_headers -o localhost https://www.google.com
#
# Example with HTTP method:
#
# cors_headers -X OPTIONS -o localhost https://www.google.com
#
# See: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
origin="localhost"
method="GET"
while getopts "o:X:" option; do
case "${option}" in
o)
origin=${OPTARG}
;;
X)
method=${OPTARG}
;;
*)
echo "No flags"
;;
esac
done
url=${@:$OPTIND:1}
echo "$method" "$url"
curl "$url" \
-X "$method" \
--header "Origin: $origin" \
-o /dev/null \
--verbose 2>&1 |
grep -E "([Aa]ccess-[Cc]ontrol|Origin|HTTP)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment