Closed jvehent closed 6 years ago
I crossed off a bunch of items since this is a static site. Please go through the rest before going live.
@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
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?
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.
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
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.
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:
value
on form entry values if the user is allowed to define CSSOther 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?
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?
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.
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:
value
directly on form elements, if the user can in any way inject inline <style>
tags to the page.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
.
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?
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
:+1:
@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.
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.
@jbuck is that the right bug? I don't see anything about missing fields there
bah, you're right, this is the correct bug: https://github.com/getsentry/sentry/issues/3542
@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?
@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
Switched assignment, because I'm not actively working on this. I think #207 covers the last bit of work here.
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
The CSP reporter has been running in production since launch, and I got a review so it's merged to master as well.
Risk Management
The service must have performed a Rapid Risk Assessment and have a Risk Record bugInfrastructure (for ops)
strict-transport-security: max-age=31536000
Public-Key-Pins: max-age=5184000; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="; pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis=";
max-age=300
) and increase progressivelyservices.mozilla.com
, it must be manually added to Firefox's preloaded pins.If service has an admin panels, it must:[x] only be available behind Mozilla VPN (which provides MFA)[x] require Auth0 authenticationDevelopment
pip list --outdated
or requires.io tooDual Sign OffServices that push data to Firefox clients must require a dual sign off on every change, implemented in their admin panelsThis mechanism must be reviewed and approved by the Firefox Operations Security team before being enabled in productionLogging
Publish detailed logs in mozlog format (APP-MOZLOG)Business logic must be logged with app specific codes (see FxA)Access control failures must be logged at WARN levelSecurity Headers
/__cspreport__
endpointdefault-src 'none'; frame-ancestors 'none'; base-uri 'none'; report-uri /__cspreport__
to disallowing all content rendering, framing, and report violationsnone
, frame-src, and object-src should benone
or only allow specific originsWeb APIs must set a non-HTML content-type on all responses, including 300s, 400s and 500sWeb APIs should export an OpenAPI (Swagger) to facilitate automated vulnerability testsSecurity Features
Authentication of end-users should be via FxA. Authentication of Mozillians should be via Auth0/SSO. Any exceptions must be approved by the security team.Session Management should be via existing and well regarded frameworks. In all cases you should contact the security team for a design and implementation reviewStore session keys server side (typically in a db) so that they can be revoked immediately.Session keys must be changed on login to prevent session fixation attacks.Session cookies must have HttpOnly and Secure flags set.For more information about potential pitfalls see the OWASP Session Management Cheet SheetAccess Control should be via existing and well regarded frameworks. If you really do need to roll your own then contact the security team for a design and implementation review.Databases
All SQL queries must be parameterized, not concatenatedApplications must use accounts with limited GRANTS when connecting to databasesIn particular, applications must not use admin or owner accounts, to decrease the impact of a sql injection vulnerability.Common issues
Apply sensible limits to user inputs, see input validationPOST body size should be small (<500kB) unless explicitely neededWhen managing permissions, make sure access controls are enforced server-sideIf handling cryptographic keys, must have a mechanism to handle quarterly key rotationsKeys used to sign sessions don't need a rotation mechanism if destroying all sessions is acceptable in case of emergency.