ViewPageSource
Back to Blog
Web Security

Top 10 Security Headers Every Website Must Have

Discover the essential HTTP security headers that protect your website from XSS, clickjacking, and data leaks. Read our 2026 developer guide with Nginx, Apache, and Cloudflare code snippets.

Alex Sterling March 8, 2026
Top 10 Security Headers Every Website Must Have

Why Web Security Headers Are Your First Line of Defense

Imagine building a brand-new house. Installing an SSL/TLS certificate (HTTPS) is like putting a lock on your front door. It is essential, but it isn't enough on its own.

What happens if an intruder tries to climb through a back window, trick you with a fake delivery, or peek through your blinds?

To protect your home completely, you need window locks, security cameras, motion sensors, and an alarm system. In the web development world, those extra layers of defense are called HTTP Security Headers.

Security headers are hidden instruction lines sent by your web server to a visitor's browser. They tell the browser exactly how to handle your site's content safely and block common cyberattacks like Cross-Site Scripting (XSS), Clickjacking, and MIME-type sniffing.

Despite their power, over 70% of websites on the internet are missing critical security headers. In 2026, failing to configure security headers doesn't just put your users at risk — it also damages your Google E-E-A-T score and website trust signals.

This guide breaks down the Top 10 Security Headers, explains how each one works in simple terms, provides server configuration code snippets (Nginx, Apache, Cloudflare), and shows you how to audit your site in seconds using ViewPageSource.

Top 10 Security Headers Shield Concept

1. Content-Security-Policy (CSP): The Ultimate XSS Shield

Content-Security-Policy (CSP) is widely considered the single most important security header ever created. It prevents Cross-Site Scripting (XSS) attacks by restricting which scripts, images, and stylesheets are allowed to load on your website.

The 8th-Grade Analogy: Think of CSP like a strict bouncer at a club door holding a VIP guest list. If a hacker tries to inject a sneaky malicious script, the bouncer checks the list, sees the script isn't approved, and throws it out!

Recommended Header Value:

Content-Security-Policy: default-src 'self'; script-src 'self' https://trusted-cdn.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:;
  • default-src 'self': Restricts all resources to your own domain by default.
  • script-src: Specifies trusted external domains allowed to run JavaScript.

2. Strict-Transport-Security (HSTS): Forcing Encrypted HTTPS

HTTP Strict Transport Security (HSTS) forces web browsers to connect to your website exclusively over secure HTTPS, preventing hackers from downgrading your connection to unencrypted HTTP.

The 8th-Grade Analogy: HSTS is like a sealed, tamper-proof security envelope. It ensures nobody can open or tamper with your letter while it travels through the mail.

Recommended Header Value:

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  • max-age=31536000: Forces HTTPS for one full year (31,536,000 seconds).
  • includeSubDomains: Applies security to all subdomains (e.g., blog.yourdomain.com).
  • preload: Submits your domain to the official browser HSTS preload list maintained by Chrome and Mozilla.

3. X-Frame-Options: Blocking Clickjacking Attacks

X-Frame-Options protects your website against Clickjacking. Clickjacking occurs when an attacker embeds your website inside an invisible <iframe> on a fake site, tricking users into clicking buttons (like "Transfer Money" or "Delete Account") without their knowledge.

The 8th-Grade Analogy: X-Frame-Options is like bulletproof, one-way mirror glass that prevents unauthorized sites from framing or spying on your website.

Recommended Header Value:

X-Frame-Options: DENY
  • DENY: Completely prevents any site (including your own) from rendering your page in an iframe.
  • SAMEORIGIN: Allows iframe embedding only if the host site shares the exact same domain.

4. X-Content-Type-Options: Stopping MIME-Sniffing Tricks

X-Content-Type-Options stops browsers from guessing (sniffing) the file type of a resource. Without this header, a hacker could upload a malicious JavaScript file masked as an innocent .jpg image, and the browser might execute it as code!

The 8th-Grade Analogy: This header is an official ID card check. It tells the browser, *"If a file claims to be a photo, treat it strictly as a photo — don't try to guess or run it as a program!"*

Recommended Header Value:

X-Content-Type-Options: nosniff

5. Referrer-Policy: Protecting User Privacy and Data Leaks

When a user clicks a link on your site to visit an external website, their browser sends a Referer header containing the URL of your page. The Referrer-Policy header controls how much private URL information is shared with destination sites.

The 8th-Grade Analogy: It is like sending a postcard where you choose whether to display your home return address or leave it completely blank.

Recommended Header Value:

Referrer-Policy: strict-origin-when-cross-origin
  • Sends full URL details for internal links, but sends only the domain name (omitting private query parameters) when linking out to external HTTPS sites.

6. Permissions-Policy: Restricting Hardware Access

Permissions-Policy (formerly known as *Feature-Policy*) lets you explicitly enable or disable access to sensitive browser hardware and APIs, such as the camera, microphone, geolocation, and payment systems.

Recommended Header Value:

Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()
  • Setting empty parentheses () disables hardware access completely, preventing unauthorized ad scripts from spying on your visitors.

7. Cross-Origin-Opener-Policy (COOP): Isolating Browsing Contexts

COOP ensures that popups and newly opened browser tabs opened from your site run in a separate browser process. This prevents malicious external sites from gaining access to your window.opener object.

Recommended Header Value:

Cross-Origin-Opener-Policy: same-origin

8. Cross-Origin-Resource-Policy (CORP): Protecting Site Assets

CORP lets you specify which third-party domains are allowed to load your images, scripts, and media files. It helps mitigate side-channel attacks like Spectre.

Recommended Header Value:

Cross-Origin-Resource-Policy: same-origin

9. Cross-Origin-Embedder-Policy (COEP): Enabling Cross-Origin Isolation

COEP requires all external resources loaded by your page to explicitly grant permission via CORS or CORP headers. Paired with COOP, it enables powerful browser features like SharedArrayBuffer.

Recommended Header Value:

Cross-Origin-Embedder-Policy: require-corp

10. X-XSS-Protection: Legacy Browser Compatibility

X-XSS-Protection was designed to enable the reflected XSS filter built into older web browsers. While modern browsers have replaced this with CSP, keeping this header active ensures backward compatibility for older legacy devices.

Recommended Header Value:

X-XSS-Protection: 1; mode=block

Summary: Top 10 Security Headers Comparison

#Security Header NamePrimary Threat PreventedRisk Level If MissingRecommended Production Value
1Content-Security-PolicyCross-Site Scripting (XSS) & Data InjectionCriticaldefault-src 'self'; script-src 'self' ...
2Strict-Transport-SecuritySSL Downgrade & Cookie HijackingCriticalmax-age=31536000; includeSubDomains; preload
3X-Frame-OptionsClickjacking & UI RedirectionHighDENY or SAMEORIGIN
4X-Content-Type-OptionsMIME-Type Sniffing & Script ExecutionHighnosniff
5Referrer-PolicySensitive URL Data & Privacy LeaksMediumstrict-origin-when-cross-origin
6Permissions-PolicyUnauthorized Camera/Mic/GPS AccessMediumcamera=(), microphone=(), geolocation=()
7Cross-Origin-Opener-PolicyCross-Window Context AttacksMediumsame-origin
8Cross-Origin-Resource-PolicyCross-Domain Asset Theft (Spectre)Lowsame-origin
9Cross-Origin-Embedder-PolicyUnauthorized Resource EmbeddingLowrequire-corp
10X-XSS-ProtectionLegacy Reflected XSSLegacy1; mode=block

Server Configuration Cheat Sheet (Nginx, Apache, Cloudflare)

Adding security headers takes less than 5 minutes. Here is how to configure them on major platforms:

Security Headers Server Configuration Diagram

Nginx Configuration (nginx.conf)

Add these lines inside your server {} block:

# Nginx Security Headers Setup
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https:; style-src 'self' 'unsafe-inline';" always;

Apache Configuration (.htaccess)

Add these lines to your .htaccess or httpd.conf file:

# Apache Security Headers Setup
<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
  Header always set X-Frame-Options "DENY"
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>

Cloudflare Transform Rules

If you use Cloudflare, navigate to Rules → Transform Rules → Modify Response Header and add header definitions visually without touching server code!


How to Audit Your Website's Security Headers

Want to check your website's security header grade?

Security Headers Audit Dashboard
  1. Go to ViewPageSource.online or use our source code analyzer.
  2. Enter your URL and click View Source.
  3. Check the Header Audit section to see your instant security grade (from A+ down to F).
  4. Review which headers are active and copy missing configuration snippets directly.

For more technical guides, check out our Website Transparency Guide and our Competitor Tech Stack Audit Guide.


Frequently Asked Questions

What are HTTP security headers?

HTTP security headers are directives sent by a web server to a user's browser in the HTTP response. They tell the browser how to enforce strict security rules, preventing common vulnerabilities like XSS, clickjacking, and data sniffing.

Why are security headers important for SEO?

Google's E-E-A-T (Experience, Expertise, Authoritativeness, and Trustworthiness) guidelines reward websites that prioritize user safety. Implementing strong security headers like CSP and HSTS sends positive technical trust signals that protect your domain authority and search rankings.

What is the difference between HTTPS and Security Headers?

HTTPS encrypts the data connection between the browser and the web server so third parties cannot eavesdrop. Security headers instruct the browser on how to execute code safely once the connection is established. You need both for complete website protection.

Will adding Content-Security-Policy (CSP) break my website?

If misconfigured, a strict CSP can block legitimate external scripts (like Google Analytics, chat widgets, or fonts). To prevent breaking your live site, start by deploying Content-Security-Policy-Report-Only, test your site for errors, and refine your rule list before switching to enforcement mode.

How do I check if my website has security headers installed?

You can check your headers instantly by entering your domain into ViewPageSource. The tool inspects your raw server headers and provides a complete security breakdown with recommended code fixes.

What is Clickjacking and how does X-Frame-Options stop it?

Clickjacking occurs when an attacker hides a transparent iframe of your site over a malicious page, tricking users into clicking buttons on your site unknowingly. The X-Frame-Options: DENY header prevents any external website from embedding your pages inside an iframe.


Conclusion: Secure Your Website in Minutes

Implementing HTTP security headers is one of the fastest, most effective ways to protect your users, boost your technical SEO signals, and elevate your brand's trustworthiness.

Don't leave your website vulnerable to preventable cyber threats.

Ready to optimize your site?

Want to test your website's security headers? Run a free security audit with ViewPageSource to inspect your HTTP headers and source code in seconds.

Audit Your Security Headers Now
HR

About the Creator: Hassan

WordPress Developer | 2 Years Experience

Hassan is the lead developer and visionary behind ViewPageSource. As a Computer Science student and WordPress specialist with 2 years of experience in custom theme and plugin development, he built this tool to bring transparency to the web. Hassan focuses on creating high-performance, developer-centric applications that help others understand and audit the technology stacks behind their favorite websites.

View PortfolioWork with Hassan →

Ready to optimize your site?

Use our professional tools to analyze your source code and technical SEO health in seconds.

Start for Free →