question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cross-Origin-Resource-Policy blocks all images

See original GitHub issue

I hope it’s ok to ask here. I have looked on stackoverflow, r/webdev, reactiflux, etc. to no avail.

Console error: “Specify a Cross-Origin Resource Policy to prevent a resource from being blocked”

On the front end, I have a regular old image element: <img src='https://uilogos.co/img/logomark/nira.png' />

On the back end, I have helmet configured:

app.use(
  helmet({
    contentSecurityPolicy: {
      directives: {
        'img-src': [
          "'self'",
          'data:',
          'https://uilogos.co/img/logomark/nira.png',
          'https://images.unsplash.com',
        ],
      },
    },
    crossOriginResourcePolicy: { policy: 'same-site' },
  })
)

I added the crossOriginResourcePolicy: { policy: 'same-site' }, option after first getting the error.

I also added cors app.use(cors()) after reading on SO that the CORP policy is intended in addition to CORS, not instead of. The only other suggestions I have found on SO are along the lines of, just don’t use that policy or set it to ‘cross-origin’ but there’s a warning in console against doing that. “⚠️If you set this header, any website can embed this resource.”

Published site

Back end repo

Do I just need to download every image I need, so to avoid any calls to other origins?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
EvanHahncommented, Nov 16, 2022

Sorry I haven’t responded here. This is still on my to-do list, but I’ve been busy.

I hope to get to it soon!

0reactions
EvanHahncommented, Nov 20, 2022

You’re embedding an image from another origin, triggering the document’s “cross-origin embedder policy”. This policy, controlled by the Cross-Origin-Embedder-Policy header, has three modes:

  1. unsafe-none, the default value. Your page can load cross-origin resources without permission from the remote origin.

    For example, your page on example.com would be able to load <img src="https://uilogos.co/img/logomark/nira.png"> with no issues.

  2. require-corp, Helmet’s default value. Your page can load cross-origin resources, but the remote origin has to give explicit permission. It can do this with the Cross-Origin-Resource-Policy header or by using CORS.

    For example, your page on example.com can load <img src="https://uilogos.co/img/logomark/nira.png"> only if uilogos.co allows it. They’d need to do some work to support this.

  3. credentialless. Your page can load cross-origin resources, but they can’t include credentials like cookies. This isn’t supported by all browsers.

I would recommend trying the credentialless policy to see if that works for you.

app.use(
  helmet({
    // ...
    crossOriginEmbedderPolicy: { policy: 'credentialless' }
  })
)

One last thing: your Content-Security-Policy looks right to me. It’s another way of restricting what your page can do, but isn’t exactly related.

I think this answers your question, so I’m going to close this issue. Let me know if that’s wrong and I’ll reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross-Origin Resource Policy (CORP) - HTTP - MDN Web Docs
Cross-Origin Resource Policy complements Cross-Origin Read Blocking (CORB), which is a mechanism to prevent some cross-origin reads by ...
Read more >
How to prevent ERR_BLOCKED_BY_RESPONSE. ...
During a cross-origin resource policy check, if the header is set, the browser will deny no-cors requests issued from a different origin/site.
Read more >
Cross-Origin-Resource-Policy (was: From-Origin) #687
Content such as images, video, and audio may be sensitive and websites ... Cross-Origin Read Blocking (CORB) automatically protects against ...
Read more >
Cross-Origin Read Blocking (CORB)
The only identified XML case that requires special treatment by CORB is image/svg+xml , which is an image type. All other XML mime...
Read more >
Cross-Origin-Resource-Policy - HTTP
The HTTP Cross-Origin-Resource-Policy response header conveys a desire that the browser blocks no-cors cross-origin/cross-site requests to the given ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found