Neova高级 SEO 平台

外部 JavaScript 文件没有子资源完整性校验

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

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

来自其他主机、没有完整性哈希的脚本,在该主机被入侵或文件被更改时仍会在浏览器中运行。这是一项安全惯例,不是搜索引擎的规定。

您可以做什么

在 script 标签上添加带有文件哈希的 integrity 属性和 crossorigin=anonymous,或把文件托管在您自己的域名上。

Neova 为何标记

  • 来自其他主机且没有完整性哈希的脚本,会运行该主机提供的任何内容,被入侵或被修改的文件会以完全权限在您的页面上运行。
  • 子资源完整性(SRI)让浏览器拒绝哈希不匹配的文件,而带版本号的文件本来就不该改变。
  • 这是一项安全惯例,不是搜索引擎的规则。

来源

完整指南

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

TL;DR

Your pages load JavaScript from a CDN, but those script tags have no integrity attribute. That means if the CDN file is swapped or tampered with, your visitors run the attacker's code and the browser never blinks. Add a Subresource Integrity (SRI) hash plus crossorigin="anonymous" to each external script, and the browser will refuse to run any file whose contents do not match the hash you trusted. Skip SRI only on files that change without a new URL, like some analytics scripts.

What This Check Flags

This audit item fires when a page pulls in JavaScript from an external host (a CDN, a third party widget, a font or charting library) using a script tag that has no integrity attribute. Your site is telling the browser to download and run code from a server you do not control, with no way to confirm the code it received is the code you expected. Every flagged tag is a spot where someone who can change that remote file can change what runs on your site.

What SRI Is and Why It Matters

Subresource Integrity lets you pin a cryptographic hash to a remote file. You compute a hash of the exact file you trust, put it in the script tag, and the browser computes its own hash of whatever it actually downloaded. If the two match, the file runs. If they do not match, the browser discards the file and never executes it.

Here is the scenario it defends against. CDNs are shared infrastructure. If one is compromised, an account is hijacked, or a file is replaced in transit, the attacker can push a modified script to every site that loads it. That script runs with full access to your pages: it can skim form fields, inject ads, redirect checkout, or steal session data. Without SRI, visitors quietly run that hostile code. With SRI, the hash no longer matches, the browser blocks the file, and the attack fails on your site. It costs you a one time hash and protects against a whole class of supply chain attacks.

The Integrity and Crossorigin Attributes

Two attributes do the work. The integrity attribute holds the algorithm and the hash, written as a prefix plus a base64 value, for example sha384 followed by a dash and the hash. SHA-384 is the common, recommended choice; SHA-256 and SHA-512 also work. The crossorigin attribute is not optional. Cross-origin files checked with SRI must be fetched using CORS, so set crossorigin="anonymous" to make the browser request the file without sending credentials. Leave crossorigin off and the browser cannot read the raw bytes it needs to verify the hash, so it "fails open" and loads the file as if no integrity check existed, quietly throwing away the protection.

<!-- BAD: no integrity, browser cannot verify the file -->
<script src="https://cdn.example.com/lib/widget.min.js"></script>

<!-- GOOD: pinned hash plus crossorigin so the check actually runs -->
<script src="https://cdn.example.com/lib/widget.min.js"
        integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
        crossorigin="anonymous"></script>

How to Generate the Hash

You can generate a hash from the command line, or use a generator like srihash.org which hands back the full tag. From a terminal, point OpenSSL at the exact file you intend to ship:

# Produce the full integrity value, prefix included
echo "sha384-$(openssl dgst -sha384 -binary widget.min.js | openssl base64 -A)"

# Output looks like:
# sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC

Hash the same versioned file the browser will fetch, then paste the result into the integrity attribute. Many CDNs and libraries already publish SRI hashes in their install snippets, so check the vendor's copy paste code before computing your own.

The Caveat: Files That Change

SRI pins one exact set of bytes. The moment the remote file changes, the hash stops matching and the browser blocks it. That is exactly what you want for a versioned library at a stable URL, where the file never changes without a new URL. It is the wrong tool for a file that updates in place under the same URL, which is how some analytics and tag scripts work. Pin one of those and your tracking can break the next time the vendor pushes an update. Rule of thumb: use SRI for stable, versioned files, and for self updating third party scripts either pin a specific version that does not move or accept that SRI does not fit. If you must keep a self updating file, plan to refresh the hash whenever it changes, ideally automated in your build.

How to Fix It

Work through the flagged tags one at a time. For each external script: confirm it loads from a stable, versioned URL; generate the SHA-384 hash of that file; add integrity with the hash and crossorigin="anonymous" to the tag; then reload the page and confirm the script still runs. On WordPress these tags usually come from a theme, a plugin, or a tag manager rather than raw HTML, so the fix may mean updating the plugin that injects the script or filtering the script output to append the attributes. Get the hash right for the exact version you serve, and re-check after any update that bumps the file.

How to Diagnose

View source or open developer tools and look at every script tag with an src pointing to another domain. Any that lack integrity are your candidates. To confirm a hash works, load the page with developer tools open and watch the Console: a mismatch produces a clear integrity error and the blocked file shows as failed in the Network tab. If a script that should run is silently missing, a wrong or stale hash is the usual culprit.

Common Mistakes

The frequent one is adding integrity but forgetting crossorigin="anonymous", which makes the browser fail open and verify nothing. Close behind is hashing the wrong file, often a different version or a non-minified copy, so the hash never matches. People also pin self updating analytics scripts and then wonder why tracking breaks. Match the hash to the exact file at the exact URL you ship.

FAQ

Q: Does SRI slow my pages down?

A: No meaningful penalty. The browser already downloads the file; hashing it is fast and happens before execution. There is no extra request and no perceptible delay for visitors.

Q: Do I need SRI on my own scripts hosted on my domain?

A: The protection is aimed at third party and CDN files you do not control. Same origin scripts you host yourself carry less risk. Spend the effort on external scripts first.

Q: Which hash algorithm should I use?

A: SHA-384 is the common recommendation and is well supported. SHA-256 and SHA-512 are also valid. Pick one strong algorithm and apply it consistently across your tags.

Need a full technical audit?

Neova runs deep crawls that catch issues like this across your whole site.

在您自己的网站上找到它

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

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

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

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

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