The page will only fail after the third-party script is replaced, to what extent can the integrity check prevent?

📅 2026-10-11 👁️ 14

After the third-party script is replaced, the page will only fail. The integrity check can prevent this kind of 'Content does not match the declaration': The browser calculates the hash of the retrieved file once according to the specified algorithm and compares it with the value written in the tag. If it is consistent, it will load; if not, it will be directly rejected and report a network error. It cannot prevent 'This host is already giving you the wrong thing'.

Which kind of attack does the check prevent?

The document clearly locates: Integrity verification is a defensive measure used to ensure that the file content retrieved by the application is exactly consistent with what is expected. A typical scenario is when an external host is taken over and content is injected into the file—the script is still the same address, the same filename, but the bytes have changed.

This type of attack is effective because most page loading logic only looks at the address and not the content. Browsers trust 'the things retrieved from that address' by default, and once the host referenced is compromised, the problem directly enters the user's session. Verifying extends the trust point from the address to the content, at the cost of having to synchronize the update of that string every time a dependency is upgraded.

How to write the integrity value, and how does the browser compare?

The syntax is to provide the Base64 hash of the algorithm and prefix while referencing external resources, the browser calculates the actual content using the same algorithm and compares it with the listed values one by one; if there is a match, it loads, and if all do not match, it refuses to load and reports a network error.

The two details are the easiest to step on:

  • When accessing resources across domains, it is necessary to declare CORS at the same time, and the tag must include the crossorigin attribute. The document explicitly states that browsers do not allow no-cors requests to use integrity checks, and requests missing this item will fail directly rather than degrading to unverified.
  • A resource can list multiple values. During grayscale release, listing the hashes of the old and new versions side by side can avoid instant widespread errors during replacement, but this is just a transitional measure, and long-term parallelism will make the verification lose its meaning.

The three types of situations it cannot block.

The first type is that the host itself is not trustworthy. The verification only guarantees that 'the content obtained is the one you specified', and if the specified content originally comes from an address that can be arbitrarily replaced, the attacker can bypass it by replacing the entire file and synchronously updating the reference value.

The second type is a replacement under the same origin path. The validation is written in the reference tag, and if the script is dynamically concatenated within the site or overwritten by other programs on the same server, changes in content and value updates may occur simultaneously.

The third type is the abuse of legitimate content. The signature is passed, and the content is correct, but the execution behavior of the script itself exceeds the scope of your authorization——for example, a statistics script sends user behavior to places it shouldn't go, and integrity verification is not involved in this layer at all.

The part that is controllable within the site is to localize the dependencies. After the third-party script is changed to self-hosted within the site, the reference address is no longer affected by external hosts, and the remaining verification points become 'who has the permission to modify this file', which falls under the category of permissions and backups. The built-in XSS protection handles content injection, while self-hosting handles source loss of control, and the two layers should not be substituted for each other.

A more stable approach within the site: to localize the dependencies.

It is recommended to arrange the order in this way: first list the inventory, list all scripts, styles, and fonts on the page that are not from the site's domain; then judge one by one whether external dependencies are necessary, and localize those that can be localized; keep the remaining external references while adding verification and cross-domain declarations; finally, incorporate the inventory into the release process, and force a reason to be stated when adding new external dependencies.

The inventory should follow the template, not rely on memory. The template centralizes the reference locations, changing one place affects the entire site, which is more reliable than maintaining each page separately.

The order of recovery after a problem occurs

Once the verification fails or the script is replaced, the order of processing affects the scope of loss.

First, break the entry: remove or modify the problematic reference from the template to point to a local copy, so that the page can recover its usability first. This step has a higher priority than locating the cause because the failure is usually manifested as the disappearance of local functions on the page, and users are still affected continuously.

Then collect the scene: keep a copy of the actual file and response header at the time of failure as a basis for subsequent comparison and accountability. This step can be overwritten by the cache clearing action, so it must be completed before cleaning.

Then verify the rollback version and data: confirm that the latest backup covers the template and static files, and can return to the state before replacement. When restoring, verify in the order of 'first program files, then data' to avoid bringing dirty files back into clean data.

Finally, do reinforcement: change this dependency to a local copy, supplement verification values, and write the reference list into the release checklist.

Common questions

Question: Isn't it the safest to add verification to all scripts?Answer: It only makes sense for resources that are indeed retrieved from external hosts. Adding verification to in-house resources does not increase protection but increases maintenance costs.

Ask: Will adding 'crossorigin' cause some users to be unable to access resources?Answer: When the server does not return the CORS header, the request will fail. Before the check, use the real network environment to verify the availability of the reference.

Ask: How often is the value updated?Answer: It follows the update of the dependency version, not the calendar. Regular batch refreshes may cause the check value and version to be disconnected, making it difficult to determine which content corresponds to which set of values when an error occurs.

Related articles

Nginx and Apache each have their place in the server software market share, and when choosing website options, which factors should be considered.

The statistics provided are of the installation distribution, not the adaptation conclusion. This article uses a public server software statistics to explain what these numbers count, why a site is counted twice, and brings the selection back to pseudo-static rules, deployment entry, memory usage, and operational familiarity.

2026-10-11

Open measurement finds that the diversity of source references of various generative engines is very different, how should it be read.

A systematic comparison study measures the natural search results with five generative search systems provided by three parties, finding that there are significant differences among the engines in terms of whether they rely on internal knowledge or external retrieval, as well as the diversity of sources. This article explains the correct interpretation of these conclusions and which paths within the site should be made machine-verifiable.

2026-10-11

The requests of the AI crawler start with encrypted signatures, can't the whitelist only look at the UA?

The new robot verification method uses HTTP message signatures to prove the identity of the crawler, and three signature-related headers need to be included in the request, with User-Agent being just one of the supplementary declarations. This article explains the difference between verifiable identity and forgeable strings, as well as where the whitelist should be written, and what the exclusion rules and anti-crawling measures each manage.

2026-10-11

Announcement for the same program has both internal and CVE numbers, which one to follow up?

When a single announcement carries both vendor internal numbers and CVE numbers, the purpose of the two sets of numbers is different: CVE is suitable for cross-product search and asset library comparison, while vendor announcements include affected version, fix branch, and disposition scheme. This article uses a list of public announcements to explain which one to follow and how to leave a record in the proprietary system.

2026-10-11

How will the cross-site redirect be affected if the SameSite attribute of the session credentials is configured to which level?

SameSite determines which requests credentials are sent with: Strict allows only the same-origin, Lax allows extra navigation that meets certain conditions, None allows cross-origin but must also be declared Secure. This article explains where the login redirect breaks at these three levels, and why the default value cannot be taken for granted.

2026-10-11

Changing the permanent redirect from 301 to 308, will the method of form submission be changed?

308 The client is explicitly required not to modify the method and request body in the redirect request; 301 also requires the same in the specification, but old clients may mistakenly use GET. This article explains what can be gained by changing numbers, what cannot be gained, and what should be confirmed first before changing the target form before the redirection.

2026-10-11

The pictures on the list page are replaced with a new generation of compression format, will the volume and crawling change together?

The compression readout given in the official document is: The new lossy format is about 50% smaller than JPEG on average, another common format is about 25%—35% smaller on average, and the lossless scenario is about 26% smaller; at the same time, it is explicitly recommended to retain the fallback format. This article explains that the volume will decrease after changing the format, but what is read depends on the image list and alternative text, and the order of implementation on the site is given.

2026-10-11

When the open source agreement is written as GPL, what should be noted when modifying and delivering to the customer.

Based on the official WordPress authorization page, the requirements of GPLv2 or later versions cover derived works, plugins and themes are considered derived works by the official, and there is a legal gray area. This article explains the three things to be delivered to the outside world, the boundary between multi-site and secondary development, as well as the authorization verification sequence at the selection stage.

2026-10-11