Use Content-Security-Policy as your primary browser-side XSS defense, and treat X-XSS-Protection as obsolete compatibility baggage. The X-XSS-Protection header was built for old browser XSS filters, while Content-Security-Policy gives you direct control over scripts, sources, inline code, and reporting. MDN marks X-XSS-Protection as non-standard and deprecated, which is enough reason not to build a modern security plan around it [source: MDN].
TLDR: Use Content-Security-Policy for real XSS risk reduction, not X-XSS-Protection. For example, a team with a 60-page customer portal can block inline scripts across the site with one strict CSP, then review reports from the 3 or 4 pages that break. X-XSS-Protection may help only in some older browsers, and it can also create odd behavior. If you can only spend one hour on browser headers this week, spend it on CSP.
What X-XSS-Protection was meant to do
X-XSS-Protection was created to control browser-based reflected XSS filters. These filters tried to detect when a script appeared in both the request and the response. If the browser thought the page was echoing attack code, it could block or sanitize the page.
A common configuration looked like this:
X-XSS-Protection: 1; mode=blockThat means the browser should enable the filter and block the page if it detects an attack. Another older option was:
X-XSS-Protection: 0That disables the browser filter. Strange as it sounds, that can be safer for some legacy sites because old filters sometimes created security issues of their own. It drives me crazy that a header with “protection” in the name can sometimes make behavior less predictable, but that is the history of this feature.

Why X-XSS-Protection is no longer enough
The core problem is simple. X-XSS-Protection depends on browser heuristics. The browser guesses whether something looks like an attack. Guessing is weak security.
Modern XSS payloads often avoid obvious reflected patterns. Stored XSS sits in a database. DOM-based XSS happens inside client-side JavaScript. Script gadgets can turn safe-looking markup into execution. Browser filters were not built to handle all of this with confidence.
There is also inconsistent support. Some browsers removed their XSS auditors. Others never supported the header in the same way. A policy that only works in some older browsers is not a control you can report as a main defense.
Common issues with X-XSS-Protection include:
- Deprecated behavior: modern browsers do not rely on it as a main security feature.
- False positives: legitimate pages may break if the filter misreads content.
- False negatives: many XSS patterns are missed completely.
- Limited scope: it mainly targets reflected XSS, not the full set of browser script risks.
- Unsafe edge cases: old filters have sometimes created new attack paths.
What Content-Security-Policy does better
Content-Security-Policy, or CSP, works in a different way. It does not ask the browser to guess whether code is bad. It tells the browser what code is allowed to run.
A strict CSP can block inline scripts, restrict external JavaScript to trusted hosts, control frames, limit form submissions, and reduce the damage caused by injection bugs. That is a much stronger model.
A basic CSP might look like this:
Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'This policy says scripts should load only from the same origin. It also blocks plugins, limits base URL abuse, and prevents the page from being framed. That is already far more useful than asking an old filter to inspect reflected input.

X-XSS-Protection vs CSP: practical comparison
| Feature | X-XSS-Protection | Content-Security-Policy |
|---|---|---|
| Main purpose | Controls old reflected XSS browser filters | Defines which resources and scripts the browser may use |
| Modern support | Weak and deprecated | Strong across modern browsers |
| Best use | Legacy compatibility only | Primary browser-side XSS mitigation |
| Control level | Low | High |
| Reporting | No serious reporting model | Can send violation reports |
The better choice is clear. CSP is the serious control. X-XSS-Protection is a legacy switch.
Should you still send X-XSS-Protection?
For most modern applications, you can set it to disabled or omit it. If your security scanner complains that the header is missing, check whether the scanner rule is outdated. Many scanners still flag missing X-XSS-Protection because old compliance templates keep hanging around. Expect to waste time on this if your organization has not cleaned up its baseline checks.
If you must include it for legacy reasons, this is the safest defensive form in many environments:
X-XSS-Protection: 0That may surprise non-security teams. The reason is that disabling a broken or inconsistent browser filter can be safer than enabling it. If your organization supports very old browsers, test before making a broad change. Do not guess.
How to build a useful CSP without breaking the site
The best CSP is strict, but strict policies can break pages that depend on inline scripts, third-party tags, or old JavaScript patterns. Start with visibility, then enforce.
- Inventory scripts. List first-party scripts, third-party scripts, analytics tags, conversion pixels, widgets, and payment scripts.
- Start with Report-Only mode. Use
Content-Security-Policy-Report-Onlyto collect violations without blocking users. - Remove unsafe inline code. Move inline scripts into files, or use nonces for scripts that must remain inline.
- Avoid broad allowlists. A policy with
script-src *gives a false sense of safety. - Block dangerous fallbacks. Avoid
'unsafe-inline'and'unsafe-eval'unless there is a short-term migration plan. - Move to enforcement. After noisy reports are fixed, switch from report-only to an active CSP.
A stronger policy with nonces may look like this:
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0mValue'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; upgrade-insecure-requestsThe nonce must be unpredictable and generated per response. Do not hardcode it. If the same nonce appears all day, attackers may reuse it.

Where CSP still needs help
CSP is powerful, but it is not a full XSS fix by itself. You still need secure coding. Encode output based on context. Validate input where it makes sense. Use safe templating. Avoid dangerous DOM APIs such as innerHTML when safer options work.
Also watch third-party scripts. If you allow a vendor script to run on your checkout page, that script can often read or change sensitive page content. CSP can restrict where scripts come from, but it cannot make a trusted script honest or bug-free.
Recommended header strategy
For a modern production application, use this order of priority:
- First: fix XSS bugs in code through output encoding, safe frameworks, and secure DOM use.
- Second: deploy a strict
Content-Security-Policywith reporting. - Third: remove dependency on inline scripts and unsafe JavaScript patterns.
- Fourth: treat
X-XSS-Protectionas legacy. Disable it or omit it based on testing and policy needs.
The practical answer is not complicated. CSP beats X-XSS-Protection for XSS defense. It is more precise, more current, and more useful during incident review. Keep X-XSS-Protection out of your main security claims. Put your effort into CSP, secure code, and routine testing.