Ravindra BagaleCourses & study guides Track your progress

Guides

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: nosniff
  • X-Frame-Options or a CSP frame-ancestors rule
  • Referrer-Policy
  • Content-Security-Policy (plan carefully)

How do I check and fix?

  1. Read live headers:
    curl -sI https://YOUR_SITE
    HTTP/2 200
    server: nginx
    content-type: text/html; charset=utf-8

    What it means: This sample response has no HSTS or XCTO yet — gaps to fix.

  2. 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.

  3. 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.

  4. Test and reload: sudo nginx -t && sudo systemctl reload nginx.
  5. 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.

Quick quiz: check what you learned

  1. Which header tells browsers to use HTTPS only for a while?

    1. Strict-Transport-Security (HSTS)
    2. X-Debug-Dump custom header
    3. Server version banner only
    4. Set-Cookie without any flags
    Show answer

    A. HSTS forces HTTPS after the first visit.

  2. What does curl -sI do?

    1. Fetch response headers only
    2. Upload a file to the web server
    3. Delete the site home page HTML
    4. Open a desktop GUI browser window
    Show answer

    A. -I is HEAD/headers; -s is silent mode.

  3. X-Content-Type-Options: nosniff mainly reduces:

    1. MIME sniffing attacks in browsers
    2. Rain damage in the data centre
    3. DNSSEC DNS signing failures
    4. 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/.