Cross-Origin-Resource-Policy (CORP)
The Cross-Origin-Resource-Policy (CORP) HTTP response header allows servers to declare which origins are permitted to embed and read the current resource (such as images, fonts, scripts, or JSON APIs).
Why CORP Matters
Modern browsers allow web pages to embed cross-origin resources using tags like <img>, <video>, or <script> by default. While traditional Cross-Origin Resource Sharing (CORS) restricts JavaScript from reading cross-origin responses, it does not stop browsers from loading those resources into browser memory.
With hardware-level CPU vulnerabilities like Spectre, malicious scripts running in the same process can inspect memory buffers and extract confidential data loaded through normal tags. CORP stops this at the source by telling the browser to abort loading the resource entirely if the requesting site is not permitted.
Supported Directives
Cross-Origin-Resource-Policy: same-origin
CORP provides three protection levels:
same-origin(Recommended for Private Sites & APIs): Only requests originating from the exact same protocol, domain, and port can read or embed this resource.same-site: Allows requests originating from the same registrable domain (e.g.api.example.comcan be loaded bywww.example.com).cross-origin: Any origin can embed the resource. Essential for public CDN assets, shared badges, or tracking pixels that are intentionally meant to be embedded across different websites.
Recommended Configuration
Apache (.htaccess)
Header always set Cross-Origin-Resource-Policy "same-origin"
Nginx
add_header Cross-Origin-Resource-Policy 'same-origin' always;
Exceptions: Public Images and Badges
If your website serves assets that are meant to be embedded on other websites (such as a dynamic verification badge or tracking pixel), you must override CORP for that specific file:
<Files "badge.php">
Header always set Cross-Origin-Resource-Policy "cross-origin"
Header always set Access-Control-Allow-Origin "*"
</Files>