Neova高级 SEO 平台

缺少 Content-Security-Policy

在 Neova 中 直接在抓取过程中运行,无需任何设置。

规则最近审核:2026年10月17日 · 指南更新:2026年7月7日

该 HTML 页面没有强制执行的 Content-Security-Policy,因此浏览器没有任何策略来限制它可以加载哪些脚本和资源文件。Report-Only 响应头不会强制执行任何内容。此项检查只查看是否有策略,不评估其强度。

您可以做什么

在 HTML 响应中发送 Content-Security-Policy 响应头,或在 meta http-equiv 标签中设置。根据 HTML 页面实际加载的来源来构建策略。

Neova 为何标记

  • 没有 Content-Security-Policy 时,浏览器没有任何规则限制页面可以加载哪些脚本和资源,注入的脚本可以随意运行。
  • CSP 是防范跨站脚本攻击(XSS)的主要手段之一;Report-Only 标头只报告,不拦截任何内容。
  • 这是一项安全惯例,不是搜索引擎的规则;Lighthouse 在 Best Practices 中审计 CSP。

来源

完整指南

这一部分目前只有英文版。

TL;DR: A Content-Security-Policy header restricts which origins can load scripts, styles, and other resources on your page. It's a security hardening measure, not a ranking factor — but a hacked site tanks rankings fast, so treat CSP as cheap insurance. Test in report-only mode, then enforce.

What a Missing Content-Security-Policy Header Means

A Content-Security-Policy (CSP) response header tells the browser which origins are allowed to load scripts, styles, images, and frames on your page, so if it's missing the browser trusts everything and a single injected <script> can run unchecked. This is a defense-in-depth measure against cross-site scripting and content injection — it is not a direct Google ranking factor, and no page has ever ranked lower for lacking one.

So why does an SEO crawler flag it? Because a compromised page is an SEO problem by proxy. Injected spam, a hacked-site warning in Search Console, or a browser interstitial will bury your rankings faster than any header ever could. CSP is the seatbelt: invisible until the day it saves you.

A Real Example and the Fix

Run a header check against a page with no policy and you get nothing back — here's a live response from a site that shipped without one:

$ curl -sI -A 'Mozilla/5.0' https://example.com/ | grep -i content-security
# (no output — header absent)

The fix is to send a policy that names your legitimate sources. A pragmatic starting policy for a typical WordPress site with a couple of third-party scripts looks like this — note it mirrors the shape of what large sites actually ship (GitHub and Cloudflare both send default-src plus explicit allow-lists):

Content-Security-Policy: default-src 'self';
  script-src 'self' 'unsafe-inline' https://www.googletagmanager.com;
  style-src 'self' 'unsafe-inline';
  img-src 'self' data: https:;
  font-src 'self' data:;
  connect-src 'self' https://www.google-analytics.com;
  frame-ancestors 'self';
  base-uri 'self';
  form-action 'self';
  upgrade-insecure-requests

After deploying, re-check and confirm the header now returns:

$ curl -sI -A 'Mozilla/5.0' https://example.com/ | grep -i content-security
content-security-policy: default-src 'self'; script-src 'self' ...

CSP Directives That Matter Most

Directive Controls Sane Starting Value
default-src Fallback for anything not named 'self'
script-src Where JS can load from 'self' + your tag manager
style-src Where CSS can load from 'self' 'unsafe-inline'
img-src Image origins 'self' data: https:
frame-ancestors Who can iframe your page (clickjacking) 'self'
upgrade-insecure-requests Rewrites http:// sub-resources to https:// enabled

How to Detect It

  1. curl the header directly: curl -sI -A 'Mozilla/5.0' https://yourdomain.com/ | grep -i content-security-policy. No line back means no policy.
  2. securityheaders.com: paste your URL and read the grade. A missing CSP knocks the score down and is called out explicitly in the report.
  3. Browser DevTools: open the Network tab, click the document request, and read the Response Headers pane. CSP violations also log to the Console in red.
  4. Screaming Frog: enable Security in the crawl config; the Security tab flags every URL missing a CSP across the whole site at once.

How to Fix It

Pick the layer you control and send the header there. Test in report-only mode first so you don't break your own page.

Apache (.htaccess)

<IfModule mod_headers.c>
  Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://www.googletagmanager.com; img-src 'self' data: https:; frame-ancestors 'self'; upgrade-insecure-requests"
</IfModule>

Nginx

add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://www.googletagmanager.com; img-src 'self' data: https:; frame-ancestors 'self'; upgrade-insecure-requests" always;

WordPress (No Server Access)

If you can't touch Apache or Nginx config, send the header from PHP in your theme's functions.php or a small must-use plugin:

add_action('send_headers', function () {
  header("Content-Security-Policy: default-src 'self'; "
    . "script-src 'self' 'unsafe-inline' https://www.googletagmanager.com; "
    . "img-src 'self' data: https:; frame-ancestors 'self'; "
    . "upgrade-insecure-requests");
});

A security plugin such as one that manages HTTP headers can do the same through a UI if you'd rather not edit code. Either way the header ends up on the response — the browser doesn't care how it got there.

Report-Only First (Do This Before Enforcing)

Swap the header name for Content-Security-Policy-Report-Only. The browser logs every violation to the console but blocks nothing, so you can watch your real traffic surface the origins you forgot — a font CDN, an embedded map, a chat widget — then add them and only then switch to the enforcing header. Enforce a policy you haven't watched in report-only mode and you will white-screen your own site. Ask me how I know.

Common Mistakes

A handful of errors account for most broken CSP rollouts:

  • Forgetting your own subdomains. If your CDN or asset host is cdn.yourdomain.com, 'self' won't cover it — name it explicitly.
  • Blocking inline styles the theme needs. Many themes inject inline CSS; omit 'unsafe-inline' from style-src and your layout collapses.
  • Setting the header twice. A plugin and the server both sending CSP produces two headers, and browsers enforce the intersection — the strictest combination, which usually breaks something.
  • Copying a huge policy off another site. GitHub's or Cloudflare's policy fits their assets, not yours. Start minimal and widen from report-only data.

FAQ

Will Adding a CSP Improve My Google Rankings?

No, not directly. Google has never listed CSP as a ranking signal. The SEO payoff is indirect: it hardens the site against the kind of hack that does tank rankings via manual actions and malware warnings.

What's the Difference Between CSP and HSTS?

CSP controls what content is allowed to load; HSTS forces the connection itself to stay on HTTPS. They solve different problems and you want both.

Will a CSP Break My Existing Scripts?

It can, which is exactly why you run Content-Security-Policy-Report-Only first. Anything not on your allow-list gets logged, you add it, and you flip to enforcing once the console is quiet.

Is 'unsafe-inline' Bad?

It weakens the policy because it re-allows inline scripts, which is what most XSS abuses. It's a common concession for WordPress themes that inline JS. Tightening to nonces or hashes is the mature next step, but a policy with 'unsafe-inline' still beats no policy.

Do I Need a CSP If I Already Run HTTPS Everywhere?

Yes. HTTPS encrypts the transport; it does nothing to stop a malicious script that's legitimately served over that encrypted connection. See our mixed content guide and the security issues glossary for how these layers stack.

在您自己的网站上找到它

Neova 在每次抓取时都会运行此检查项和其他所有检查项,然后把修复方法写成工单交给您的团队。

  • 适用于 Mac、Windows 和 Linux 的桌面应用
  • 全部 696 项检查,每项都附来源
  • Search Console 和 Analytics 4,以只读方式连接
  • 工单发送到 Jira、Linear 和 Asana

下载 Neova Desktop Free 套餐,或免费试用 Solo 14 天,无需银行卡。

全部安全检查 · 指南 · 检查项库

作者:Neova Labs · 返回检查项库