XenonStack

Cyber Security

XenonStack Blog HTTP Security Headers: CSP, HSTS and XSS Guide

and | Published | Updated

HTTP Security Headers: CSP, HSTS and XSS Guide
15:35

Key takeaway

  • Guide to HTTP security headers for CISOs and architects: CSP, HSTS, nosniff, CORS, CORP and COEP, what is deprecated, and how XSS is really stopped.

What are HTTP security headers and what do they protect against?

HTTP security headers are response headers a server sends so that the browser applies extra rules to a page: which scripts may run, whether the page may be framed, whether the connection must use HTTPS, and which other origins may read its resources. They narrow what the browser will do, which limits the damage when an application has a cross-site scripting (XSS), clickjacking or content-sniffing flaw. They sit beside secure coding, not in place of it. The OWASP XSS Prevention Cheat Sheet treats Content Security Policy (CSP) as defence in depth, not as the primary fix.

For a CISO or platform lead, the practical answer is a short baseline: a strict CSP, HSTS, nosniff and a framing rule, with CORS, CORP and COEP set deliberately where cross-origin access matters. Several headers older guides recommend, such as X-XSS-Protection, are now deprecated. This guide covers what each header does, what has changed, how to roll them out without breaking pages, and when they do not help. It builds on our work on adaptive security architecture and website security.

Which security headers belong in an enterprise baseline?

The table uses MDN and the OWASP HTTP Headers Cheat Sheet as sources. Status is as read on 12 November 2026.

HeaderWhat it doesWhen it fitsCurrent status
Content-Security-PolicyRestricts which sources may load scripts and other content; frame-ancestors controls framingEvery web application, rolled out in report-only mode firstPrimary browser-side control against XSS impact; defence in depth, not a replacement for encoding
Strict-Transport-SecurityTells the browser to use HTTPS only for the host for a set timeAny site fully served over HTTPSCurrent. Preload needs max-age of at least 31536000 and includeSubDomains
X-Content-Type-Options: nosniffBlocks MIME sniffing; blocks scripts and styles served with the wrong typeEvery responseCurrent. Needs correct Content-Type on all resources
X-Frame-OptionsAllows DENY or SAMEORIGIN framing onlyFallback for legacy browsers beside CSP frame-ancestorsALLOW-FROM is obsolete; frame-ancestors is the more flexible control
Referrer-Policy, Permissions-PolicyLimit referrer data and browser featuresSites handling sensitive URLs or embedding third partiesOWASP suggests strict-origin-when-cross-origin for Referrer-Policy
CORS headersLet a server allow named origins to read its responsesAPIs called from other originsCurrent. Wildcard origin cannot be used with credentials
Cross-Origin-Resource-PolicyResource owner blocks no-cors loads from other sites or originsSensitive resources and API responsesCurrent
Cross-Origin-Embedder-PolicyDocument only loads cross-origin resources that opt inPages that need cross-origin isolationCurrent. Values: unsafe-none, require-corp, credentialless
X-XSS-ProtectionLegacy browser XSS filterNot for new workDeprecated and non-standard; MDN recommends CSP instead

What has changed in HTTP security headers?

  • X-XSS-Protection is deprecated. MDN marks it deprecated and non-standard, warns that it can create XSS vulnerabilities in otherwise safe sites, and recommends CSP. The OWASP cheat sheet advises not to set it. If it is still sent, X-XSS-Protection: 0 avoids the filter-related problems MDN describes.

  • Framing is now a CSP job. X-Frame-Options: ALLOW-FROM is obsolete and modern browsers ignore the header when they see it. Use Content-Security-Policy: frame-ancestors 'none' unless the page must be embeddable, and keep DENY or SAMEORIGIN only as a legacy fallback.

  • Strict CSP replaces allowlists. MDN describes nonce-based and hash-based strict policies as easier to maintain than host allowlists, which are hard to get right.

  • Reporting has moved. MDN recommends the Reporting API (Reporting-Endpoints with report-to) and marks report-uri deprecated, while suggesting both are declared until support is universal.

How do XSS attacks work and what stops them?

In cross-site scripting, an attacker gets a script to run in a victim's browser in the context of a trusted site. OWASP describes the cause as an application putting untrusted data into a page in a way that lets the browser treat it as code. There are three common forms.

Two-column diagram mapping XSS, clickjacking, content sniffing and HTTP downgrade to strict CSP with encoding, frame-ancestors, nosniff and HSTS

What is stored XSS?

The application saves attacker input, for example a comment, and renders it raw to later visitors. Anyone who loads the page runs the script, which can read page data or redirect the user. The fix is output encoding for the context where the data lands, plus a maintained sanitiser such as DOMPurify where users may submit HTML.

What is reflected XSS?

The script arrives in a request parameter, such as a name in a URL, and the server echoes it in the response. The victim usually has to follow a crafted link. Server-side output encoding is the control; user vigilance is not.

What is DOM-based XSS?

Client-side JavaScript reads an attacker-controllable source, such as the URL, and writes it into the page through an unsafe sink. OWASP advises safe sinks such as textContent over innerHTML, avoiding eval(), and allowing only expected URL schemes (not javascript:). Trusted Types, where supported, help enforce this.

Why are headers not enough on their own?

OWASP states that input filtering, interceptors and web application firewalls do not replace context-aware encoding and safe DOM use, and that CSP should not be the primary defence. Treat headers as the layer that limits impact when a flaw slips through. For testing both layers, see our guide to SAST, DAST, IAST and SCA and the application security best practices guide.

How should you configure Content Security Policy?

A CSP is a set of semicolon-separated directives. MDN's strict examples use a nonce or hash and also set object-src 'none' and base-uri 'none'.

When does a nonce-based policy fit?

The server generates an unpredictable value for every response, puts it in the policy and in the nonce attribute of the intended script tags. The browser runs only scripts whose nonce matches. Because the value changes per response, the HTML cannot be served as static files. Insert nonces only into your own tags.

Content-Security-Policy:
  script-src 'nonce-{RANDOM}';
  object-src 'none';
  base-uri 'none';

When does a hash-based policy fit?

You hash each script with SHA-256, SHA-384 or SHA-512, Base64-encode it and list it with the matching prefix. External scripts also need an integrity attribute. This suits static pages and client-rendered single-page applications, but any script change means recomputing and redeploying the hash.

Content-Security-Policy:
  script-src 'sha256-{HASHED_SCRIPT}';
  object-src 'none';
  base-uri 'none';

Two cautions from MDN. Browsers ignore 'unsafe-inline' when a directive contains nonce or hash expressions. 'strict-dynamic' eases third-party scripts but is less secure if trusted scripts build script elements from XSS-prone input.

How do you roll out CSP without breaking pages?

Send Content-Security-Policy-Report-Only first. It is not enforced but reports violations, and it cannot be delivered in a meta element. Our engineering teams have used this pattern on embedded applications, adding report-only headers first so that embed compatibility was kept while violations were reviewed. Move to enforcement once the reports are clean.

How do CORS, CORP and COEP differ?

HeaderWho sets itQuestion it answersValues or behaviour
CORS (Access-Control-Allow-Origin and related)The server being calledWhich other origins may read this response?A named origin; no wildcard when credentials are used
Cross-Origin-Resource-PolicyThe resource ownerWho may load this resource in no-cors mode?same-site, same-origin, cross-origin
Cross-Origin-Embedder-PolicyThe embedding documentWill this page load only resources that opted in?unsafe-none (default), require-corp, credentialless

A request is simple, and skips preflight, only if the method is GET, HEAD or POST, manually set headers are CORS-safelisted, and Content-Type is application/x-www-form-urlencoded, multipart/form-data or text/plain. Anything else triggers an OPTIONS preflight, whose result can be cached with Access-Control-Max-Age. Setting COEP with Cross-Origin-Opener-Policy: same-origin makes a document cross-origin isolated, which features such as SharedArrayBuffer need. Our API development best practices post covers where these controls sit in API design.

What should you know about HSTS before enabling it?

HSTS only takes effect after the browser has received the header once over HTTPS, so the first insecure request stays exposed unless the domain is preloaded. Preload requires max-age of at least 31536000, includeSubDomains and preload, and MDN notes it is hard to undo, so confirm every subdomain serves HTTPS first. Each subdomain should send its own header, and browsers offer no click-through on certificate errors for HSTS hosts.

How do you roll out headers across a large estate?

  1. Inventory. List applications, owners and where headers are set (application, reverse proxy, CDN).

  2. Set the safe defaults. nosniff, a framing rule and HSTS where HTTPS is complete.

  3. Run CSP in report-only mode. Review reports, then enforce per application.

  4. Set cross-origin policy deliberately. Named CORS origins, CORP for sensitive resources, COEP only where isolation is needed.

  5. Make it a release check. Verify headers in the pipeline so a deployment cannot silently drop them.

The same control-and-evidence thinking applies to AI agents that call your web applications. ElixirData Context OS, according to its site, supplies enterprise AI agents with trustworthy context, checks what they are allowed to do before they act, and logs every decision for audit. AgentGRC offers governance, risk and compliance controls for autonomous agent actions. See also agentic AI security.

When do security headers not help?

  • They do not fix the underlying flaw. Unencoded output remains a vulnerability even behind a strong CSP.

  • A weak policy gives false comfort. A CSP that allows 'unsafe-inline' without nonces or hashes does little against injected inline script.

  • Wrong Content-Type values plus nosniff will block legitimate scripts and styles.

  • Headers protect the browser side only. They do not secure the server, the API logic or stored data.

What are the business impacts of XSS?

A successful XSS attack can expose session tokens or personal data, let an attacker act as a user, send users to phishing pages and damage trust in the brand. If personal data is exposed, privacy obligations may apply, so involve your data protection and legal teams in incident planning.

To map one browser-security decision your agents and applications depend on, and the context and policy behind it, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

Should we still send X-XSS-Protection?

No. MDN marks it deprecated and non-standard and recommends CSP. If it is still sent, a value of 0 avoids the filter problems MDN describes.

Is X-Frame-Options still needed?

Use CSP frame-ancestors as the primary control. DENY or SAMEORIGIN can remain as a fallback for legacy browsers. ALLOW-FROM is obsolete.

Nonce or hash for CSP?

Nonces suit dynamically generated responses because the value changes per response. Hashes suit static or client-rendered pages but need recomputing whenever a script changes.

How do we test a CSP safely?

Send Content-Security-Policy-Report-Only first, review the violation reports, then enforce. Report-only cannot be set in a meta element.

Can we use Access-Control-Allow-Origin: * with cookies?

No. For credentialed requests the server must name an explicit origin and send Access-Control-Allow-Credentials: true, otherwise the browser blocks the response.

What does HSTS preload require?

A max-age of at least 31536000, includeSubDomains and preload, submitted through hstspreload.org, which MDN notes is not part of the HSTS specification.

Recommended Next Steps for Implementation

Engage with our specialists about implementing effective HTTP security headers. Discover how various industries utilize these headers and strategies to create robust defenses against XSS attacks. Leveraging security headers enhances web application safety, automating protection measures and optimizing response times, ultimately improving overall efficiency and security posture.

 

Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.

Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in Solving your Challenges with XenonStack Team
Get Started

Get Started with your requirements and primary focus, that will help us to make your solution

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Proceed Next