Content security policy reports first and does not block, deciding to really block after seeing what happens
Use the report-only mode of Content Security Policy first, and decide to block after seeing what information. This is the most stable order when launching this rule. The document speaks directly: The report-only approach is used for the testing phase, reports violations without blocking code execution. Its value does not lie in 'being gentle first', but in giving you a list of violations generated under real access conditions, from which you can decide which ones to block and which ones to modify the page first.
What problem does the only report mode solve?
The most common incident when directly enabling interception is the failure of page functionality: styles are blocked, third-party components cannot be loaded, and interactions report errors after inline scripts are disabled. These are often not fully visible in the test environment because real access is mixed with browser extensions, proxy injection, and different versions of clients.
The reporting mode separates judgment and execution: rules are evaluated as usual, violations are recorded as usual, and the page is rendered as usual. This allows you to collect data for one to two weeks without affecting visitors, distinguishing between 'sources that must be allowed' and 'injections that must be blocked'. This step is especially important for content-centric sites, as inline styles and embedded content in rich text are most likely to be mistakenly damaged.
Why do we need to write the report target twice
There are two ways to write the reporting address: the old address type and the new endpoint type. The document indicates that the new writing style is designed to replace the old one, and in browsers that support the new style, the old instructions will be ignored. This means that writing only one place will result in two bad situations - only write the old style, and the new browser will not report; only write the new style, and the old client will not report.
The practice during the compatibility period is to provide both: old addresses and new endpoint names in the same strategy, and also to declare the actual receiving address of the endpoint. The receiving end should do deduplication because the same violation may be reported twice in different formats. The report address itself should use an in-site path or a same-domain endpoint, and additional handling is required for cross-domain reporting, which is also the reason why many sites do not receive reports.
During the gray release period, what types of information should be looked at?
The first category is the most frequent source of violations, usually consisting of three types: embedded content, statistical scripts, and browser extension injection. The first two should be explicitly stated in the strategy, and the third should be excluded from the records—their domain names are varied, but none of them are under your controlled code. Mistaking them for targets to be intercepted will make the rules increasingly broad.
The second category is inline scripts and inline styles. Rich text on content sites often includes inline attributes, and directly banning them will distort the layout. For this category, either modify the template to extract the styles out, or accept a broader exception, based on the actual proportion in the violation records.
The third category is resources redirected to elsewhere. The strategy matches the source based on the final address, and resources with redirects are often judged to be违规. These should be changed to direct addresses at the source, rather than making exceptions for redirects.
Fallback when enabling interception
Switch by segment: intercept a few paths first, confirm there are no violations, and then expand to the entire site. Keep a fallback method, so that you can immediately revert to only reporting in case of functional failures, rather than temporarily adding exceptions to the strategy—temporary exceptions often do not come back.
When modifying the template, this layer needs to be checked together. The visual template editing capability within the site will affect both style references and script references at the same time. When modifying the public header and footer, the allowed writing styles of the strategy should be checked together; otherwise, the page will become blank after the template is modified, and the problem will be reported in the strategy.
Common questions
How long does it take to report only?Cover a complete content and event cycle, usually counted for one to two weeks, festival sites should include peak periods; a short period of time will miss the rare embedded forms.
How to troubleshoot if reports are not received?Please confirm that the report address is accessible, whether it is blocked by the same-origin restriction, whether both writing methods have been given, and whether the receiving end has discarded duplicate records.
Can we turn off the interceptor and only keep the report?Yes, if we only report long-term, it is equivalent to no protection, just treat it as a transition; after confirming that the violations are controllable, we should switch off the interceptor.
What is the reason for the sudden increase in the number of violations?Most of them come from third-party scripts changing domain names or template changes, first compare the source of violations with the time of the last template and dependency changes, rather than rush to add exceptions.