-
Notifications
You must be signed in to change notification settings - Fork 177
Add Content Security Policies and set up reporting #1068
Comments
Hmm, there are some fiddly complications. Mostly because I would like to get the git sha in the report-uri as the sentry "release". But because the ansible project is independent from the frontend deployment it does not have the git sha available. A few options:
I think I'll go with 4 for now, as it's so simple. |
Oh, 4 is not possible as you cannot use a https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-uri |
I progressed, but still a few decisions, and maybe some related tasks. So I tried option 3c (not mentioned above) - which is to have a little nodejs proxy server that listens for But I also thought it makes sense to unify frontend/backend deployment a bit too - currently frontend is deployed via circleci without ansible and just needs to deploy built artifacts, whereas backend deploys via circleci using ansible and deploys by checking out the git repo on the remote server and builds statics there. It might be nice to deploy both via built artifacts (although the fully built/installed backend project is ~500mb due to the sizable pip libs - but could leave out those). ... but I think I'll go back to putting it in yuca and ignore the release part. |
Ok, reporting is setup! Still in report-only mode. I'll leave it on that for a bit and see which things I might have missed. Reports go into https://sentry.io/foodsaving-worldwide/karrot-csp-report-only/ for both dev and prod (tagged as The first report to get through is the non-https image on https://karrot.world/#/groupPreview/47 - this would be blocked if I turned it on properly, this is actually good as it should remove the mixed content warnings in the browser, but maybe we should put a note somewhere that you can't include http: images. |
I see three messages in the console when visiting karrot.world and dev.karrot.world:
However, I don't see a related report at https://sentry.io/foodsaving-worldwide/karrot-csp-report-only/ Other reports have arrived in the meantime (besides the non-https image)
|
Apparently CSP reports from Firefox are disregarded by Sentry because they miss a value: getsentry/sentry#2475 |
Yes I noticed that. I think we can just use chrome to get the policy right. Then just wait until the world around us gets fixed. |
Hmmm, still shows inline/eval errors on https://dev.karrot.world/. Service worker is missing |
I see these errors in Firefox, but not in Chromium. There are also no reports lately when visiting dev.karrot.world with Chromium: https://sentry.io/foodsaving-worldwide/karrot-csp-report-only/?environment=development&query= |
Maybe our windows users don't do geocoding so frequently, but still useful when they do :) |
CSP is enabled for dev.karrot.world now :) Seems ok so far, I can browse around the website on firefox/chrome/app. |
https://dev.karrot.world/bundlesize.html doesn't work any more :/ Can see it with:
... but not ideal... guess we need some overrides for that path. |
Fixed the bundlesize.html page now. It still shows some Firefox still shows errors for the main page too, but it can't back them up with any evidence.... it works, and the line number does not make sense. |
I found the eval usage in regenerator runtime facebook/regenerator#336 We have 4 versions of the library in our lockfile. Some of them older. We could just wait until everything upgrades in the future and it should resolve itself. |
) |
Closing as done! |
@nicksellen proposed to set up some CSPs for karrot-frontend to enhance security. They consist of an HTTP header that we should probably configure in ansible and add a reporting service.
Documentation about CSP: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
Our ansible playbooks without CSP: https://github.com/yunity/yuca
Using sentry as a CSP reporting service: https://docs.sentry.io/learn/security-policy-reporting/
My idea would be to start with report-only policies, to get better insight in the effects that an enforced policy would have. I already started a sentry project that could be used for it: https://sentry.io/foodsaving-worldwide/karrot-csp-report-only/
The text was updated successfully, but these errors were encountered: