How to Check HTTP Security Headers with curl
Run curl -sI https://YOUR_SITE and look for strict-transport-security, x-content-type-options, x-frame-options or content-security-policy, and referrer-policy. Missing headers are easy wins on your Nginx or Apache host.
Quick answer
curl -sI https://YOUR_SITE | tr -d '\r' | grep -iE 'strict-transport|content-security|x-frame|x-content-type|referrer-policy|permissions-policy'Why check security headers?
Headers are cheap controls. They cut clickjacking, cookie leaks over HTTP upgrades, and some XSS paths. Diego in São Paulo and Kavya in Coimbatore both put header checks in their go-live list.
What should you look for?
Strict-Transport-Security(HSTS)X-Content-Type-Options: nosniffX-Frame-Optionsor a CSPframe-ancestorsruleReferrer-PolicyContent-Security-Policy(plan carefully)
How do I check and fix?
- Read live headers:
curl -sI https://YOUR_SITEHTTP/2 200 server: nginx content-type: text/html; charset=utf-8What it means: This sample response has no HSTS or XCTO yet — gaps to fix.
- Filter the important ones:
curl -sI https://YOUR_SITE | tr -d '\r' | grep -iE 'strict-transport|content-security|x-frame|x-content-type|referrer-policy' || echo 'NONE FOUND'What it means: If you see NONE FOUND, add headers next.
- Add a starter set in Nginx (your site):
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header X-Frame-Options "SAMEORIGIN" always;What it means: Starter headers. Tune CSP separately so you do not break scripts.
- Test and reload:
sudo nginx -t && sudo systemctl reload nginx. - Re-run curl and tick items on the checklist.
Ravindra Bagale's Tip
Add HSTS only after HTTPS works everywhere (including www and apex). Premature HSTS with a broken cert locks browsers out. Leila in Amman waits one clean week of HTTPS before max-age goes high.
Ravindra Bagale's Tip – मराठी
HSTS तेव्हाच द्या जेव्हा HTTPS सर्वत्र चालते (www आणि apex). चुकीच्या cert सह HSTS browser ला लॉक करते. अम्मानमधील लैला एक स्वच्छ आठवडा वाट पाहते मग max-age वाढवते.
Ravindra Bagale's Tip – हिंदी
HSTS तभी दो जब HTTPS हर जगह चलता हो (www और apex)। गलत cert के साथ HSTS ब्राउज़र लॉक कर देता है। अम्मान की लैला एक साफ़ हफ़्ता बाद max-age बढ़ाती है।
Quick quiz: check what you learned
Which header tells browsers to use HTTPS only for a while?
- Strict-Transport-Security (HSTS)
- X-Debug-Dump custom header
- Server version banner only
- Set-Cookie without any flags
Show answer
A. HSTS forces HTTPS after the first visit.
What does curl -sI do?
- Fetch response headers only
- Upload a file to the web server
- Delete the site home page HTML
- Open a desktop GUI browser window
Show answer
A. -I is HEAD/headers; -s is silent mode.
X-Content-Type-Options: nosniff mainly reduces:
- MIME sniffing attacks in browsers
- Rain damage in the data centre
- DNSSEC DNS signing failures
- Battery drain on your laptop
Show answer
A. nosniff stops browsers guessing content types.
Learn it properly
This guide is the short path. These pages go deeper, with labs:
Frequently asked questions
What is the curl command for security headers?
curl -sI https://SITE then filter the names you care about.
What does HSTS do?
Tells browsers to use HTTPS only for a period (max-age).
Is a missing CSP always critical?
CSP is powerful but easy to break apps. Start with XCTO and HSTS, then craft CSP carefully.
Can I test HTTP (port 80)?
Yes, but security headers matter most on HTTPS responses.
Related tool?
Website security checklist under /cyber/tools/.