Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we tighten up our CSP? #11943

Open
2 of 7 tasks
alexgibson opened this issue Jul 19, 2022 · 9 comments
Open
2 of 7 tasks

Can we tighten up our CSP? #11943

alexgibson opened this issue Jul 19, 2022 · 9 comments
Assignees

Comments

@alexgibson
Copy link
Member

alexgibson commented Jul 19, 2022

Description

https://observatory.mozilla.org/analyze/www.mozilla.org

We currently allow both unsafe-inline and unsafe-eval in script-src, but I'm not 100% sure if anything we're using today is relying on those?

Might we also be able to remove unsafe-inline from style-src?

Possible things to check:

  • Webpack might use eval() but only in dev mode. In prod mode it should not be needed.
  • Convert is still a thing on our site for A/B testing, but has not been used for a long time?
  • Does GA/GTM require any of the above? Not to my knowledge, but worth checking.

Success Criteria

  • We get an improved score for CSP in Mozilla Observatory.

Tasks

  1. Backend
    stevejalim
@alexgibson
Copy link
Member Author

Same also applies for Pocket mode ^

@alexgibson alexgibson added this to the Technical Roadmap Q3 2022 milestone Jul 19, 2022
@alexgibson alexgibson modified the milestones: Technical Roadmap Q1 2023, Technical Roadmap Q2 2023 Dec 6, 2022
@alexgibson alexgibson modified the milestones: Technical Roadmap Q2 2023, Technical Roadmap Q3 2023 Jun 19, 2023
@alexgibson
Copy link
Member Author

GTM CSP guidelines for future reference: https://developers.google.com/tag-platform/security/guides/csp

stephaniehobson added a commit that referenced this issue Nov 28, 2023
stephaniehobson added a commit that referenced this issue Jan 3, 2024
@alexgibson
Copy link
Member Author

@janbrasna
Copy link
Contributor

After CSP reporting is in place #14453, is there a chance to add another, more restrictive policy header, as Content-Security-Policy-Report-Only e.g. without the unsafe inlines, to let the usual traffic help identifying places that might be still using these? Can django-csp send both "real" and CSP_REPORT_ONLY, or it's either-or but not both?

@stevejalim
Copy link
Collaborator

Ah, @janbrasna I think you just stumbled across the one thing we need to add to django-csp before we can ask the Django project to fold it into core mozilla/django-csp#36

@janbrasna
Copy link
Contributor

janbrasna commented Apr 23, 2024

@stevejalim 🤦 gotcha, next time I need to utfg, this time I only rtfd and didn't look further;)

To update the original post:

(I still can't seem to get to the bottom of the local dev webpack websockets and whether that would need adding to connect-src for dev extras… but investigating why the ws: is not covered by self in the first place…)

I think the quick win in the ratings is also to disallow object-src completely if it's not used anywhere.

@robhudson
Copy link
Member

Just to add here, the latest beta release of django-csp will allow adding a report-only CSP. As @janbrasna pointed out above, we could enable that without the unsafe-inline and/or unsafe-eval and see what's tripping it.

@janbrasna
Copy link
Contributor

The last inlined style was removed in #14614 and I couldn't find any more of such occurrences so hopefully the unsafes can be gone soon.

Also disabling object-src completely should be possible.

@janbrasna
Copy link
Contributor

janbrasna commented Jul 29, 2024

Just adding one piece of the puzzle that hasn't been mentioned before I guess — when tightening the individual policies instead of appending the defaults everywhere eventually, a reasonable set of hosts should be picked for every rule, as wildcards can basically mean stuff can get linked from addons.m.o, support.m.o and similar "user generated content":

csp

So e.g. tighten *.mozilla.net to assets.mozilla.net for images and code.cdn.mozilla.net for fonts etc. (effectively not allowing e.g. interactive-examples.mdn.mozilla.net content via wildcards…); explore what mozorg subdomains besides www.m.o need to have stuff hotlinked from and constrain the wildcard etc. …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

4 participants