Strapi admin blocks uploaded images and media because of its CSP
Refused to load the image 'https://res.cloudinary.com/...' because it violates the following Content Security Policy directive: "img-src 'self' data: blob: market-assets.strapi.io".Short answer
Strapi's default strapi::security middleware limits images and media to 'self'. When uploads live on S3, Cloudinary or another host, the admin panel blocks them. Replace the plain string with an object in config/middlewares and add the provider's domain to img-src and media-src. Check no environment file overrides it.
Fix it fast
1Find out which cause you have
Read the host named in the console violation, then look at how the security middleware is listed in your config. A bare string means the defaults are in force.
grep -n "security" config/middlewares.js config/middlewares.ts config/env/*/middlewares.* 2>/dev/null2Match what you see, then jump to its fix
What does the error look like?
Refused to load the image 'https://res.cloudinary.com/...' because it violates the following Content Security Policy directive: "img-src 'self' data: blob: market-assets.strapi.io".Refused to load media from 'https://bucket.s3.eu-west-1.amazonaws.com/...' because it violates the following Content Security Policy directive: "media-src 'self' data: blob:".
Cause 1 of 2
The upload provider's domain is not in img-src and media-src
1Check
The Strapi docs say the default security middleware has a strict contentSecurityPolicy that limits images and media to 'self', and that an external upload provider's domain must be allowed. Your config/middlewares file probably still has the string 'strapi::security'.
grep -n "strapi::security" config/middlewares.*2Fix
Replace the string with an object that keeps useDefaults and lists your provider host in both directives. The Strapi example for S3 also keeps data: and blob: and sets connect-src to 'self' and https:.
// config/middlewares.js
module.exports = [
'strapi::logger',
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'market-assets.strapi.io', 'res.cloudinary.com'],
'media-src': ["'self'", 'data:', 'blob:', 'market-assets.strapi.io', 'res.cloudinary.com'],
upgradeInsecureRequests: null,
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
];3Verify
Restart Strapi, open the Media Library and confirm the previews load with no violation in the console.
npm run developConfirmed by docs.strapi.io
Cause 2 of 2
An environment middleware file replaces your change
1Check
The Strapi Cloud docs state that a config/env/production/middlewares file fully replaces the global middleware array. If it exists, your edit in config/middlewares is not used in production.
ls config/env/production/2Fix
Put the same security object in the environment file, and keep the whole middleware array there, because it replaces the global one entirely.
// config/env/production/middlewares.js: same array as above,
// with the 'strapi::security' object including your provider domain3Verify
Deploy, then open the Media Library in production and read the console.
npm run buildConfirmed by docs.strapi.io
How do I stop it coming back?
- Whenever you add an upload provider, update the security middleware in the same commit.
- Keep one middleware list per environment in version control, and diff them.
- Keep market-assets.strapi.io in the lists; the Strapi docs say it is safe to keep.
- Read the browser console after every provider change.
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?
Projects of mine built on the same technologies:
Related fixes
Back end
Node.js says the hostname does not match the certificate's altnames
code: 'ERR_TLS_CERT_ALTNAME_INVALID'
Node.js compares the host you connect to with the subjectAltName entries of the server certificate.
3 causes, each with a fixBack end
Node.js warns that NODE_TLS_REJECT_UNAUTHORIZED is set to '0'
UNABLE_TO_VERIFY_LEAF_SIGNATURE
Node.js prints this warning because the variable NODE_TLS_REJECT_UNAUTHORIZED equals '0', which turns off certificate checks for every TLS connection in the process.
3 causes, each with a fixBack end
Nodemailer fails to send mail: connection timeout, TLS or login errors
ETIMEDOUT with timeoutType connect, greeting, upgrade or socket
Read err.code first: Nodemailer sets it for every failure.
3 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fix