KKorrali Web

Security headers › Cross-Origin-Resource-Policy

How to add the Cross-Origin-Resource-Policy header in Next.js

CORP lets you say which origins may load your resources, such as images and scripts.

Next.js configuration (next.config)

async headers() {
  return [
    {
      source: "/:path*",
      headers: [{ key: "Cross-Origin-Resource-Policy", value: "same-origin" }],
    },
  ];
}

Add the headers() function to your Next.js config and restart or redeploy. Headers set by a proxy or CDN in front can override these.

Before you deploy

Use same-site or cross-origin for assets that other sites or your CDN subdomains legitimately load.

Verify it works

curl -sI https://your-site.com | grep -i cross-origin-resource-policy

Or run a free Korrali Web scan to check this and every other security header at once.

Scan your site free

Other headers in Next.js