When your own image is directly referenced by other websites, which response header decides whether to allow or not.
When your own image is directly referenced by other websites, which response header determines whether to allow it or not? The authority of this header lies with the resource itself, not the site referencing it. Cross-Origin-Resource-Policy is a strategy declared by the resource itself: it tells the browser which sources are allowed to load this resource, and cross-site requests that do not match the declaration are blocked on the client side. Whether to allow or restrict is determined by the response headers of the resources on your own site, and the other site does not need to cooperate.
Who has the authority to declare which resources can be referenced.
A layer of confusion lies in the fact that the page and the resources it can reference belong to two parties. On the side of the initiating page, the isolation header says 'What am I allowed to bring in this context?' and on the side of the resource declaration, it says 'Who can use this thing of mine.' Whether the same cross-site reference can be made depends on the intersection of the declarations on both ends, and any tightening on either end will cause the load to fail. Therefore, when troubleshooting, do not just focus on the error page, but also whether there is a suitable strategy in the response header of the referenced resource, which is another independent clue.
The three values are placed to pass through which layer
| Value | Pass through which layer | Suitable for what type of resource | The cost after being released |
|---|---|---|---|
| same-origin (same origin) | Only pages from the same origin can be loaded | Background attachments, internal preview images | The site's own domain changing protocol or port will cause it to be unreadable |
| same-site (same site) | Multiple origins under the same registered domain can be loaded | A set of materials shared by the main site and its sub-sites | Any sub-site within the same registered domain can refer to it, and the scope of dissemination is no longer controlled |
| cross-origin (cross origin) | Any other origin can be loaded | Images and fonts to be distributed externally | Others' sites directly consume your bandwidth and access statistics |
The issue between the three levels is not a matter of preference between leniency and strictness, but about who is allowed to use the resources. The same file can have different values in different directories, and the granularity is determined by the response.
Which type of requests are blocked by default?
This strategy targets cross-origin or cross-site requests without CORS, that is, requests for images, scripts, and styles that are loaded directly as sub-resources. When the browser reads the tightening statement, it blocks these requests at the client side, while the response of the resource itself is still emitted normally, and the server does not participate in the judgment. This determines its scope of action: it can control whether the browser displays the resources, but cannot prevent someone from directly requesting files by bypassing the browser.
Whether to release images and fonts separately
Images are often referenced from outside, tightening the same origin will immediately make them invisible on other sub-sites of your own, and loosening to cross-origin will consume bandwidth. Fonts often must be loosened to cross-origin because the pages referencing them are originally from other sites, blocking them means the font will fail across the entire site. The choice between the two is usually differentiated by directory: materials that need to be distributed follow a path with a loose declaration, while materials used exclusively on-site are kept tight.
This declaration can't block anything.
The anti-crawling interference code within the site is aimed at how to deal with the content after it is taken away - it acts on the main content, used to reduce the quality of the things obtained in bulk. The resource source strategy is another layer, just dealing with the browser loading step. Treating both as the same thing can easily lead to the judgment bias of 'the pictures are all there, but the text has been taken away by the collection'. If you really want to reduce the consumption of direct citations, you need to go back to the source statement, directory division, and access control.
Common questions
Question: Is it enough to only change the isolation header of the initiating page?Answer: Not enough. The declaration on this side of the referenced resource is independent, both ends must be allowed to load successfully; when the resource side tightens, the page side will not relax even if it is loose.
Question: Will changing the protocol or port affect the same-origin judgment?Answer: Yes. Same-origin looks at the protocol, host, and port, and if any one of them is different, it is not considered the same origin. Such changes often judge the originally normal images as cross-origin.
Question: If it is set to cross-origin, does it mean allowing crawling?Answer: Not equal. This level only determines whether the browser allows a certain source to load this resource, and has no constraint on the direct request for file crawling behavior.