Inline base64 images do not show because of the Content Security Policy
Refused to load the image 'data:image/png;base64,iVBORw0KGgo...' because it violates the following Content Security Policy directive: "img-src 'self'".Short answer
A base64 image has a data: URL, and a policy such as default-src 'self' does not allow that scheme. Images are governed by img-src, and by default-src when img-src is absent. Add data: to img-src, check for a second policy that also blocks it, and keep the list of other sources short.
Fix it fast
1Find out which cause you have
Find which directive is named in the console message, then look for img-src in the real response headers. If it is absent, default-src is the one in force.
curl -sI https://example.com/ | grep -i "content-security-policy" | tr ';' '\n' | grep -iE "default-src|img-src"2Match what you see, then jump to its fix
What does the error look like?
Refused to load the image 'data:image/png;base64,iVBORw0KGgo...' because it violates the following Content Security Policy directive: "img-src 'self'".Refused to load the image 'data:image/svg+xml;base64,...' because it violates the following Content Security Policy directive: "default-src 'self'".
Cause 1 of 3
img-src lists sources but not data:
1Check
MDN describes img-src as the directive for images and favicons, and it accepts scheme sources. The CSP specification says non-HTTP schemes have to appear in the source list, so an image whose URL starts with data: is blocked unless data: is there.
curl -sI https://example.com/ | grep -i "content-security-policy" | tr ';' '\n' | grep -i "img-src"2Fix
Add the data: scheme to img-src. Keep your other sources as they are.
Content-Security-Policy: default-src 'self'; img-src 'self' data:3Verify
Reload without cache. The inline images should render and the console should be quiet.
curl -sI https://example.com/ | grep -i "img-src"Confirmed by developer.mozilla.org
Cause 2 of 3
There is no img-src, and default-src decides
1Check
MDN says that when img-src is absent the browser uses default-src. With default-src 'self' every image that is not from your own origin is refused, data: ones included.
curl -sI https://example.com/ | grep -i "content-security-policy" | tr ';' '\n' | grep -iE "default-src|img-src"2Fix
Add a separate img-src. That way you open only images and leave scripts, frames and the rest on default-src.
Content-Security-Policy: default-src 'self'; img-src 'self' data:3Verify
Reload and check the console for the violation message.
curl -sI https://example.com/ | grep -i "content-security-policy"Confirmed by developer.mozilla.org
Cause 3 of 3
A second policy still blocks data:
1Check
The CSP specification says several policies can apply to one resource, and each enforced policy is checked. A meta tag in the HTML, a CDN rule or a framework middleware may add one next to yours.
curl -s https://example.com/ | grep -i "http-equiv=.content-security-policy"
curl -sI https://example.com/ | grep -ic "content-security-policy"2Fix
Change the policy where it really comes from, or make every enforced policy allow data: for images. Prefer one policy.
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' data:">3Verify
Reload the page and confirm only the expected policy is sent.
curl -sI https://example.com/ | grep -i "content-security-policy"Confirmed by w3.org
How do I stop it coming back?
- Write img-src explicitly, with the data: scheme only if you really inline images.
- Prefer files served from your own origin for large images; base64 inflates the HTML.
- Trial each policy change with the Report-Only header before it is enforced.
- Keep one place that sets 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 fixSecurity
The browser refuses to load a font because of your Content Security Policy
Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.
A font is blocked when the font-src directive, or default-src when font-src is missing, does not allow where the font comes from.
3 causes, each with a fixSecurity
Video from a MediaSource is blocked: 'Content at ... may not load data from blob:'
Content-Security-Policy: The page's settings blocked the loading of a resource (media-src) at blob:http://localhost:3000/...
A MediaSource video plays from a blob: URL.
3 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fixSecurity
Your auth.log is full of Failed password and Invalid user attempts
Invalid user ubnt from 198.51.100.23 port 40122
Any public SSH port gets password guesses within hours; the log lines alone are not a breach.
4 causes, each with a fixSecurity
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fix