You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[v4]Content Security Policy issue of plugin-upload in strapi-4.0.0-beta.13 #11637
changed the title [-]Content Security Policy issue of plugin-upload in strapi-4.0.0-beta.13[/-][+][v4]Content Security Policy issue of plugin-upload in strapi-4.0.0-beta.13[/+]on Nov 19, 2021
@boeto The internal middleware config change is not documented but I found out you can change default CSP settings middleware in config/middlewares.js like this:
Reacted by Mason, Bence Husi, Matheus Custodio, smoothdvd, spyesx, Torin Taylor, Cory Robinson, ruichao.ma, thpo, Gregdams and 93 more
Reacted by Qhoirul Anwar, Ironman, Ali Alnoaimi, Torin Taylor, Saša Gašparović, Jacob Gonzalez, Cory Robinson, Dante Chun, Burhan Yılmaz, Yurii Holskyi and 31 more
Reacted by Mohamad Fala, Sietze Keuning, Matheus Custodio, Rowan-Paul, Pablo Delfante, Dante Chun, modoespacial, Burhan Yılmaz, Ahmed Riyad, Nirmal Savinda and 37 more
Reacted by AliSaeed090, bragamat, stoXmod, Shehroz Ali, Israel Outeiro, owaissultan, Sỹ Phú and wangjing
In S3 bucket config I had to make my bucket public. I think the Strapi - Amazon AWS - Create the bucket doc is wrong because the bucket must be public, contrary to what the documentation says.
Based on S3 User guide I added a Bucket policy to my bucket
After configuration, you should check the images directly in a browser with the S3 Object URL. If everything went well, you can see the picture uploaded by Strapi. If the configuration failed and an error message is displayed, the Bucket is probably still not public.
Important!
According to the AWS user guide, creating a public S3 bucket is dangerous and should only be done if you are hosting a static website. In my opinion the uploaded images are part of a static website and in this situation it is acceptable, but I am not an AWS expert. Please consider not using the public S3 bucket if you are not comfortable with it!
Screenshots of my S3 Bucket config
Another beautiful day has passed to find this bug :)
I'm trying to make a upload on a Strapi project with a provider (default config, I guess). But al get it response is Refused to connect to 'http://my-url/upload/' because it violates the following Content Security Policy directive: "connect-src 'self' https:".
With a Status Code 301
But the request url was https://my-url/upload The request go through a nginx but why does it respond on http instead of https? Everything else works in the admin panel, only the uploads dont.
I haven't been able to fix it and don't know what to do.
My console logs this error:
Refused to load the image 'https://s3.us-east-1.amazonaws.com/my-bucket-stuff/thumbnail_1700242274671_05530326c8.jpeg?updatedAt=2024-07-09T05%3A26%3A13.053Z' because it violates the following Content Security Policy directive: "img-src 'self' data: blob: https://s3.us-east-1.amazonaws.com/my-bucket-stuff".
I tried adding a wildcard like '/*' in the S3 URL but it doesn't work the only thing that has shown to work is to directly place the entire URL in the "img-src" array but that's obviously wrong.
Please, somebody help me, I've stuck here for days, it's the exact same start on both URLs and the wildcard seems to not be working, I'm so frustrated.
Activity
[-]Content Security Policy issue of plugin-upload in strapi-4.0.0-beta.13[/-][+][v4]Content Security Policy issue of plugin-upload in strapi-4.0.0-beta.13[/+]grzegorzbialy commentedon Nov 23, 2021
@boeto The internal middleware config change is not documented but I found out you can change default CSP settings middleware in config/middlewares.js like this:
derrickmehaffy commentedon Dec 6, 2021
Provider examples will have an example config to show how to properly modify this. Closing as it's not a bug
derrickmehaffy commentedon Jan 4, 2022
This issue has been mentioned on Strapi Community Forum. There might be relevant details there:
https://forum.strapi.io/t/strapi-v4-broken-image-even-when-the-images-link-works-cloudinary/14143/4
derrickmehaffy commentedon Jan 5, 2022
This issue has been mentioned on Strapi Community Forum. There might be relevant details there:
https://forum.strapi.io/t/strapi-v4-override-csp/14157/2
ludovicraymond commentedon Feb 2, 2022
Doesn't work for me for video assets.
It's ok for image type.
any idea ?
nsavinda commentedon Feb 25, 2022
https://dev.to/kevinadhiguna/what-is-cors-how-to-configure-cors-in-strapi-461b
strapi-bot commentedon Mar 18, 2022
This issue has been mentioned on Strapi Community Forum. There might be relevant details there:
https://forum.strapi.io/t/using-supabase-for-the-postgres-database/16762/2
13 remaining items
kepes commentedon Jan 27, 2023
Based on Strapi docs I put
midlewares.jsintoconfig/env/productionfolder. This way dev and prod environment separated.This is my working
midlewares.jscontent. I putAWS_REGIONinto the URLIn S3 bucket config I had to make my bucket public. I think the Strapi - Amazon AWS - Create the bucket doc is wrong because the bucket must be public, contrary to what the documentation says.
Based on S3 User guide I added a
Bucket policyto my bucketAfter configuration, you should check the images directly in a browser with the S3 Object URL. If everything went well, you can see the picture uploaded by Strapi. If the configuration failed and an error message is displayed, the Bucket is probably still not public.
Important!
According to the AWS user guide, creating a public S3 bucket is dangerous and should only be done if you are hosting a static website. In my opinion the uploaded images are part of a static website and in this situation it is acceptable, but I am not an AWS expert. Please consider not using the public S3 bucket if you are not comfortable with it!
Screenshots of my S3 Bucket config
Another beautiful day has passed to find this bug :)
nikita-fuchs commentedon Mar 8, 2023
@carloshs94
Damn, that was my mistake, too, you saved me !
nikantkamat commentedon Mar 23, 2023
Is there any same fix for the plugin "strapi-uploader-provider-do" because i am getting the same error
strapi-bot commentedon Jun 29, 2023
This issue has been mentioned on Strapi Community Forum. There might be relevant details there:
https://forum.strapi.io/t/content-security-policy-on-shared-hosting-with-two-nodejs-aps/29654/4
dynamic-standard2 commentedon Aug 4, 2023
If anyone has issues with the images of Strapi's Marketplace, add "market-assets.strapi.io" to the img-src and media-src directives, like this:
andersonstudioa commentedon Aug 11, 2023
I fixed changing the file
config/middlewares.tswithCDN_URLbrun0xff commentedon Nov 22, 2023
For god's sake thank you, you're awesome!
LeNguyenMinhTuan commentedon Jan 30, 2024
I'm stuck here too. Did you solve it ?
jsphkhan commentedon Feb 5, 2024
This is the solution to follow if anybody is using a CDN in front of S3 bucket. I was using a Cloudfront instance on top of AWS S3.
Kamarhinanton commentedon Jul 4, 2024
Does enyone know, why after transferring data to prod, url is broken in reach text block? In media galery picture is ok.

nikita-fuchs commentedon Jul 4, 2024
Because your fileURL is pointing to
localhost, which is not a thing of course when you deploy things somewhere else.Kamarhinanton commentedon Jul 4, 2024
How I can change this behaviour? On my local machine everything is ok with this text reach block.
H3lltronik commentedon Jul 9, 2024
I haven't been able to fix it and don't know what to do.
My console logs this error:
Refused to load the image 'https://s3.us-east-1.amazonaws.com/my-bucket-stuff/thumbnail_1700242274671_05530326c8.jpeg?updatedAt=2024-07-09T05%3A26%3A13.053Z' because it violates the following Content Security Policy directive: "img-src 'self' data: blob: https://s3.us-east-1.amazonaws.com/my-bucket-stuff".This is my config/middlewares.js
I tried adding a wildcard like '/*' in the S3 URL but it doesn't work the only thing that has shown to work is to directly place the entire URL in the "img-src" array but that's obviously wrong.
Please, somebody help me, I've stuck here for days, it's the exact same start on both URLs and the wildcard seems to not be working, I'm so frustrated.
I'm running strapi 4.25.2
javdevruent commentedon Sep 19, 2024
@H3lltronik have you ever fix this issue?
DannyST89 commentedon Oct 8, 2024
Thanks ,it works for me.