mozilla / FirefoxColor

Theming demo for Firefox Quantum and beyond
https://color.firefox.com
Mozilla Public License 2.0
452 stars 94 forks source link

Backend Security Checklist #67

Closed jvehent closed 6 years ago

jvehent commented 6 years ago

Risk Management

Infrastructure (for ops)

Development

Dual Sign Off

Logging

Security Headers

Security Features

Databases

Common issues

jvehent commented 6 years ago

I crossed off a bunch of items since this is a static site. Please go through the rest before going live.

jbuck commented 6 years ago

@jvehent two quick q's about the checklist:

Access and application logs must be archived for a minimum of 90 days

So that'd mean configuring the Cloudfront logs and storing them for 90 days, correct?

a report-uri pointing to the service's own /cspreport endpoint

Is there a csp reporter that someone has configured for a static site before? I think it'd be possible to do with Lambda Edge if someone hasn't figured this out already

jvehent commented 6 years ago

So that'd mean configuring the Cloudfront logs and storing them for 90 days, correct?

Yep, that's correct.

Is there a csp reporter that someone has configured for a static site before?

Not that I'm aware. I wonder if we want to relax this requirement for sites that don't handle authentication, which would make your life easier. @psiinon, any thoughts?

jbuck commented 6 years ago

Two more clarifications needed :)

If the service is not hosted under services.mozilla.com, it must be manually added to Firefox's preloaded pins.

How do I go about adding themer.firefox.com to Firefox's preloaded pins?

no use of unsafe-inline or unsafe-eval in script-src, style-src, and img-src

I had to enable unsafe-inline in style-src. @lmorchard do you know if it's possible to not set inline styles? Given the extensive uses of colour pickers, I can see how it'd be difficult to avoid setting inline styles.

lmorchard commented 6 years ago

I had to enable unsafe-inline in style-src. @lmorchard do you know if it's possible to not set inline styles? Given the extensive uses of colour pickers, I can see how it'd be difficult to avoid setting inline styles.

Yeah, I think this project is pretty reliant on inline styles for the theme previews that involve arbitrary user-selected colors. I can scratch my head on it for a bit, but I'm fairly sure we can't get around that one

jvehent commented 6 years ago

How do I go about adding themer.firefox.com to Firefox's preloaded pins?

I think we'll skip that in this instance. It's a code change in Firefox (hard to do) and themer is only a testpilot experiment, so the risk is low.

Yeah, I think this project is pretty reliant on inline styles for the theme previews that involve arbitrary user-selected colors. I can scratch my head on it for a bit, but I'm fairly sure we can't get around that one

Allow me to cast an @april spell on this CSP, and with a bit of luck, she'll help find a solution here.

april commented 6 years ago

In general I am okay with the use of 'unsafe-inline' inside style-src. There are a few anti-patterns that you should watch out for though:

Other than that, your big concern is phishing, which is annoying but not the end of the world. I will add that the CSP3 working group is considering proposals to add something like 'unsafe-inline-attr' where style= would be allowed but not <style> tags. That's a ways off at best though.

There are some other ways that might be more workable. Do you have a dev site I could poke at to look at the implementation?

lmorchard commented 6 years ago

There are some other ways that might be more workable. Do you have a dev site I could poke at to look at the implementation?

Sure: https://mozilla.github.io/Themer/

lmorchard commented 6 years ago

FWIW, I think the main spots where we run into trouble with inline styles are these components:

https://github.com/mozilla/Themer/blob/master/src/web/lib/components/AppBackground/index.js#L16 https://github.com/mozilla/Themer/blob/master/src/web/lib/components/BrowserPreview/index.js

These want to apply dynamic styles for colors & background images based on user selections while building a theme.

april commented 6 years ago

In general, I don't have much issue with using 'unsafe-inline' inside style-src. It's not overly risky, and I understand that it can place a high complexity burden on sites that wish to avoid it.

There are a couple of anti-patterns (that we know of) that can allow attackers to do attacks purely in CSS, such as you can see here. Namely:

Otherwise, the main risk with inline styles is phishing attacks. As long as you're very careful with how user inputs get translated onto the page, that can be largely avoided.

Note that the CSP3 working group is working on changes to CSP3 that would allow style= attributes while disallowing <style> tags, fixing most of the risk:

https://github.com/w3c/webappsec-csp/issues/45

But obviously that's a ways away, both from implementation in a browser and in the spec.

Based on what I see with themer, it seems like you should be able to do what you're doing now, without using inline styles. Here is a quick and dirty example:

https://www.twoevils.org/html/test/csp-set-style-no-unsafe-inline-style.html

Inline styles are blocked, but JavaScript is still updating the background color. Again, I'm not sure how complex it would be to rearchitect things to work with React in this manner. If that complexity is high, I'm personally not overly worried about 'unsafe-inline' remaining inside style-src.

psiinon commented 6 years ago

I'd recommend having a csp reporter even if theres no auth. Its a good way to find out if the site is broken, eg by a change thats got through testing but is still blocked by the CSP. Obviously this only helps if we monitor the CSP reports. What do we do for other services? Can we just do the same, but maybe with lower priority alerting?

jbuck commented 6 years ago

Right now I'm using a Lambda function to add custom security headers. I think it would be trivial to do something like have it forward CSP reports to Sentry which also has the advantage of notifying developers that something broke

psiinon commented 6 years ago

:+1:

jvehent commented 6 years ago

@jbuck FYI sending violation reports to a different location means that the blocked_uri field of the report will only contain the domain and not the full path. This is why we recommend sending violation reports to the same origin. I suppose you could proxy the reports to sentry and get the best of both worlds.

jbuck commented 6 years ago

Update: I was able to get CSP reports over to Sentry pretty easily. The problem is that Sentry currently doesn't accept CSP reports from Firefox because it's missing some fields in the payload.

ghost commented 6 years ago

@jbuck is that the right bug? I don't see anything about missing fields there

jbuck commented 6 years ago

bah, you're right, this is the correct bug: https://github.com/getsentry/sentry/issues/3542

ghost commented 6 years ago

@jbuck what's the next step? We can't report CSP errors from Firefox? Or we can just fake those fields in your Lambda function?

jbuck commented 6 years ago

@wresuolc hmm, we could definitely have a lambda function fake those fields, yeah. That seems like a reasonable approach here. I'll update this bug when that's done

lmorchard commented 6 years ago

Switched assignment, because I'm not actively working on this. I think #207 covers the last bit of work here.

jbuck commented 6 years ago

I have a patch up for review at https://github.com/mozilla-services/cloudops-deployment/pull/2013 that outputs any CSP reports to Cloudwatch Logs, which is a good enough starting point for the security review to go ahead. Once it's been reviewed, I'll deploy to production

jbuck commented 6 years ago

The CSP reporter has been running in production since launch, and I got a review so it's merged to master as well.