A command-line tool built in Python to analyze the HTTP security headers of a given URL. This script helps assess a website's security posture by checking for key headers like Content-Security-Policy
(CSP) and Strict-Transport-Security
(HSTS) that are crucial for defending against common web vulnerabilities.
- Analyzes any given URL for the presence of important security headers.
- Provides clear, color-coded output for found (✅ Green) and missing (❌ Red) headers.
- Handles connection errors and bad server responses gracefully.
- Accepts the target URL as a simple command-line argument.
- Python 3.x
-
Clone the repository (replace
your-username
with your actual GitHub username):git clone [https://github.com/your-username/Python-Security-Header-Analyzer.git](https://github.com/your-username/Python-Security-Header-Analyzer.git)
-
Navigate to the project directory:
cd Python-Security-Header-Analyzer
-
Create and activate a virtual environment:
# Create the venv python -m venv venv # Activate on Windows .\venv\Scripts\activate # Activate on Mac/Linux source venv/bin/activate
-
Install the required packages:
pip install -r requirements.txt
Run the script from your terminal, followed by the full URL you want to analyze.
python analyzer.py <url>
Examples
Analyzing a secure site:
Bash
$ python analyzer.py [https://github.com](https://github.com)
✅ Success! Connected to [https://github.com](https://github.com) (Status Code: 200)
--- Security Header Analysis ---
✅ [FOUND] Content-Security-Policy
✅ [FOUND] Strict-Transport-Security
--- Summary ---
✅ Secure: All critical security headers were found.
Analyzing a less secure site:
Bash
$ python analyzer.py [http://example.com](http://example.com)
✅ Success! Connected to [http://example.com](http://example.com) (Status Code: 200)
--- Security Header Analysis ---
❌ [MISSING] Content-Security-Policy
❌ [MISSING] Strict-Transport-Security
--- Summary ---
❌ Not Secure: One or more critical security headers are missing.
Handling user error:
Bash
$ python analyzer.py
Usage: python analyzer.py <url>