Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Video from a MediaSource is blocked: 'Content at ... may not load data from blob:'

ErrorContent at http://localhost:3000/ may not load data from blob:http://localhost:3000/...

Short answer

A MediaSource video plays from a blob: URL. If your Content-Security-Policy has no media-src, the browser uses default-src, and 'self' does not cover blob:. Add blob: to media-src (and to worker-src if a blob worker is blocked). Check that no second policy, such as a meta tag, still blocks it.

  • Applies to Firefox current release, Chrome current release
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the policy the server really sends and look for media-src. If it is missing, default-src is what blocks the blob: URL.

    curl -sI http://localhost:3000/ | grep -i "content-security-policy" | tr ';' '\n' | grep -iE "default-src|media-src|worker-src|child-src"
  2. 2Match what you see, then jump to its fix

    1. 1The console names media-src, or default-src when the policy has no media-src.media-src is missing and default-src does not list blob:Fix
    2. 2The blocked resource is a blob: URL and the directive named is worker-src, child-src or script-src.The blob: URL belongs to a worker, and worker-src blocks itFix
    3. 3You added blob: to the header but the same violation message keeps appearing.A second policy is also enforced and it still blocks blob:Fix

What does the error look like?

  • Content at http://localhost:3000/ may not load data from blob:http://localhost:3000/...
  • Content-Security-Policy: The page's settings blocked the loading of a resource (media-src) at blob:http://localhost:3000/...

Cause 1 of 3

media-src is missing and default-src does not list blob:

1Check

MDN says media-src covers audio and video elements, and that the browser falls back to default-src when media-src is absent. The CSP specification says non-HTTP schemes must be named in a source expression. A policy of default-src 'self' therefore does not allow blob: URLs.

curl -sI http://localhost:3000/ | grep -i "content-security-policy" | tr ';' '\n' | grep -iE "default-src|media-src"

2Fix

Add an explicit media-src that includes the blob: scheme next to your own origin.

Content-Security-Policy: default-src 'self'; media-src 'self' blob:

3Verify

Reload the page with the cache disabled and start the video. The console should show no new violation.

curl -sI http://localhost:3000/ | grep -i "media-src"

Confirmed by developer.mozilla.org

Did this fix it?

Cause 2 of 3

The blob: URL belongs to a worker, and worker-src blocks it

1Check

MDN lists the fallback order for worker-src as child-src, then script-src, then default-src. If your player starts a Worker from a blob: URL, the first of those directives that exists must allow blob:.

curl -sI http://localhost:3000/ | grep -i "content-security-policy" | tr ';' '\n' | grep -iE "worker-src|child-src|script-src"

2Fix

Put blob: in worker-src. That one directive controls Worker, SharedWorker and ServiceWorker scripts, so you do not have to loosen script-src.

Content-Security-Policy: default-src 'self'; media-src 'self' blob:; worker-src 'self' blob:

3Verify

Reload and watch the console while the player starts.

curl -sI http://localhost:3000/ | grep -i "worker-src"

Confirmed by developer.mozilla.org

Did this fix it?

Cause 3 of 3

A second policy is also enforced and it still blocks blob:

1Check

The CSP specification says multiple policies can apply to one resource, and each enforced policy must pass. A policy in a meta tag, or one added by a proxy or a framework, is checked in addition to your header.

curl -s http://localhost:3000/ | grep -i "http-equiv=.content-security-policy"
curl -sI http://localhost:3000/ | grep -ic "content-security-policy"

2Fix

Keep one source of truth. Remove the meta tag or the extra header, or add blob: to every enforced policy.

<!-- delete this line, or add media-src 'self' blob: to it -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">

3Verify

Reload the page. Only one policy should show in the response headers and the video should load.

curl -sI http://localhost:3000/ | grep -i "content-security-policy"

Confirmed by w3.org

Did this fix it?

How do I stop it coming back?

  • List media-src and worker-src explicitly in every policy, instead of relying on the default-src fallback.
  • Try policy changes with Content-Security-Policy-Report-Only first, then enforce.
  • Keep the policy in one place, so a header and a meta tag cannot disagree.
  • Test video in Firefox as well as Chrome when you change the policy.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Security

The browser blocks a script because of your Content Security Policy

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

The page's Content-Security-Policy does not allow what it tried to run or load.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.