Add integrity verification to external scripts, why do you still need to explicitly write cross-domain attributes in the tag?

📅 2026-10-11 👁️ 5

When adding integrity checking to external scripts, the cross-domain attribute must also be explicitly written in the tag, because the check depends on the premise of cross-domain requests. The document states: Since the resources that require integrity checking must use cross-domain requests, the cross-domain attribute must be included in the tag. Without it, the browser's access method to such resources is inconsistent with the check requirements, and the check value cannot be determined, resulting in the resource being directly rejected for loading, or the check is virtually ineffective.

At what step does the check occur?

It occurs after resource download and before execution: the browser calculates the summary of the content and compares it with the value given in the tag. If they do not match, the resource is not used. It protects the section of 'reference not replaced', which is the scenario where the content distribution node or the external script source is replaced. It does not protect what the script itself does. The script that is often replaced is the entry point for cross-site scripting (XSS), and this check reduces the probability of 'loading a file tampered with passively'. What the file does after loading still depends on source restrictions.

So it is suitable for hanging on to version-fixed third-party scripts and styles. References that change with the content are not suitable to be added, because each update of the source file will cause the verification to fail, and the page will directly lack styles or interactions.

Why must the cross-domain attribute be explicitly written

The cross-domain attribute determines the mode in which the request is issued. By default, the use of scripts and styles does not carry complete cross-domain semantics, and the response received by the browser cannot safely participate in summary comparison. After explicit declaration, the request is issued in cross-domain mode, and verification has comparable input.

The most common accident is to add the check value but forget to write the cross-domain attribute: It is not noticeable during local testing due to cache hits, but resource loading fails after going online. Conversely, if only the cross-domain attribute is written without the check, there is no check effect at all. The two types should appear in pairs.

Writing points Common mistakes The appearance when it occurs
Check value and cross-domain attribute are paired Only give the check value Resource is refused to load, page lacks style or no interaction
Multiple algorithm options Only give a single summary The entire site fails at the same time after changing the algorithm in the source file
Version fixed reference Validate dynamic content Failure triggered on each update
Review after batch replacement Only change script, not style Half of the references still use the old summary

The format of the validation value matches the alternative

The value is a summary of one or more content pieces, separated by whitespace. Each summary consists of an algorithm prefix, a hyphen, and an encoded hash value. The allowed prefixes are sha256, sha384, and sha512. The value of providing multiple summaries is in the transition: the source file can be loaded normally as long as any of them matches during the next update, and the site does not need to replace all references at the same time during the same release window.

When generating an abstract, use the actual file distributed as the standard, do not use the source file before compression and merging; if there are construction steps in the middle, take the hash on the construction output, otherwise, the content online will not be consistent with the calculation basis.

Batch verification on the template side

Reference points are usually scattered in the common header and footer of the template. When making changes, both scripts and styles need to be updated. There is a station-wide replacement tool suitable for batch repairing such reference points, but after batch changes, it must be reviewed: replacements are made based on text matching, and writing differences across templates (attribute order, whether parameters are included) are easy to miss a part.

The more stable sequence is to first run the full station reference list on the test station, request each resource with verification one by one, confirm that the summary is consistent with the output, and then go to production. If the template changes are made simultaneously with the in-station visual template editing capability, after the change is completed, still check against the same list, the editing capability will not verify the online summary for you.

Common questions

Will the CDN certificate replacement fail after verification?No, verification only compares the file content summary and is unrelated to the transport layer certificate; but if the CDN makes compression and rewriting of the file, it will fail.

Do you need to add internal scripts?Resources that are the same domain and change with construction do not need to be added, the value is concentrated on external references with fixed versions.

Will there be a prompt if the validation fails?The browser console will record, and ordinary visitors will only see missing functions, so during the gray release period, it is necessary to actively compare the reference list.

Can we only provide a single algorithm for a long time?Yes, but when changing algorithms, all references must be changed at once; providing two summaries can stretch the transition period.

Related articles

Content security policy reports first and does not block, deciding to really block after seeing what happens

Content Security Policy runs in only-report mode first, used to collect violation records without blocking execution, which is a gray-scale method before going live with intercept rules. There are two ways to write the report target, new browsers will ignore the old address, and both should be written during the compatibility period. This article explains what types of information to look at during the gray period, when to cut off the intercept, and how to avoid a blank screen when changing the template.

2026-10-11

The large attachment upload is blocked at 413, why is it not understandable in the browser?

When uploading a large attachment, it is blocked by the gateway and returns 413. Browsers often cannot display the reason because the limit is set before the request enters the application, and the program does not have time to take over. The default limit for this type of nginx is about one megabyte, which can be set by segment according to the site and location. This article explains which segment the limit controls, why the error is difficult to read, and how to check the three types of entry points for attachment upload, batch import, and interface upload.

2026-10-11

What codes should be returned for deleted articles and hidden columns, and what consequences will there be if they are all compressed into 404?

When deleting content or hiding columns, if the status code is unified to 404, the still existing paths will be read as expired. This article gives the landing points for the four types of semantics: delete, hide, reject, and exception, and explains how the recycling station, draft, and pending publication status within the site correspond to the front-end return, and attaches a list of standards for reference

2026-10-11

How will the front-end sorting and push be chaotic when the scheduled publication time zone difference is taken into account

Schedule publishing so that content transitions from pending to official at the specified time. Time zone differences can cause the overall launch time to shift, which may affect the sorting of content by release time on the front end and the timing of link promotions. First, clarify the visibility scope of the three states: pending, official, and recycling bin. Then, unify the time zone standards and verify the release time together during backup and recovery.

2026-10-11

How many addresses can a single sitemap file hold, and how should it be split if it exceeds the limit?

The single sitemap file has two concurrent limits: the number of addresses should not exceed 50,000, the uncompressed volume should not exceed 50MB, and any that reach the top must be split into multiple fragment files, and then a index file is used to list the fragments one by one. This article explains how to calculate the limit according to the original protocol, how to name the fragment directory stably, the division of labor between the index file and the sub-maps, as well as the pseudo-static rules and configuration to check when the background automatically generates the sitemap, to avoid bypassing the limit by trimming the number of addresses in an erroneous manner.

2026-10-12

How to fill in the last modified time in the sitemap so that it is easy to be accepted.

The last modified time in the sitemap should be filled in according to the actual change: the protocol requires the use of W3C Datetime format, which can only be written as a date; changefreq and priority are defined as hints rather than instructions, and full-site refresh will only make the crawler treat this field as noise. This article explains the protocol meaning of this field, the four common ways it is filled incorrectly, how to obtain the real change time from the content status, and the time scope to be noted when配合 with timed publishing.

2026-10-12

Forms and comments are flooded by robots, besides the captcha, what else can be done to add several layers?

Form and comment anti-robot spambot prevention, CAPTCHA only blocks the automatic submission layer, and cannot block scripts that have bypassed verification and low-cost manual submissions. The layered叠加 can be: submission verification (reCAPTCHA CAPTCHA, timestamp and honeytrap fields), content filtering (sensitive word filtering, keyword replacement, content review), publishing strategy (review before posting, pending publication status, frequency limit and login threshold). This article explains the limitations of each layer, as well as what to adjust when all three layers cannot block it.

2026-10-12

Whether to install the preview version on the production station, and how to choose between Release Candidate and formal version

The candidate version is at the final stage of the release process, the purpose is to let people verify the upcoming packaged final version, not the version for daily use on production stations. This article uses the recent example of Joomla simultaneously releasing 6.2 candidate version and 5.x, 6.x dual branch security repair announcements to explain where the candidate version should run, which branch to upgrade first when running dual version lines in parallel, and the backup and rollback points that must be prepared before the upgrade.

2026-10-12