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

Security Checklist #31

Closed
37 of 43 tasks
jvehent opened this issue Nov 30, 2018 · 10 comments
Closed
37 of 43 tasks

Security Checklist #31

jvehent opened this issue Nov 30, 2018 · 10 comments
Labels
security Anything that has an impact on security

Comments

@jvehent
Copy link

jvehent commented Nov 30, 2018

Risk Management

  • The service must have performed a Rapid Risk Assessment and have a Risk Record bug
  • The service must be registered via a New Service issue

Infrastructure

  • Access and application logs must be archived for a minimum of 90 days
  • Use Modern or Intermediate TLS
  • Set HSTS to 31536000 (1 year)
    • strict-transport-security: max-age=31536000
    • If the service is not hosted under services.mozilla.com, it must be manually added to Firefox's preloaded pins. This only applies to production services, not short-lived experiments.
  • If service has an admin panels, it must:
    • only be available behind Mozilla VPN (which provides MFA)
    • require Auth0 authentication

Development

  • Ensure your code repository is configured and located appropriately:
    • Application built internally should be hosted in trusted GitHub organizations (mozilla, mozilla-services, mozilla-bteam, mozilla-conduit, mozilla-mobile, taskcluster). Sometimes we build and deploy applications we don't fully control. In those cases, the Dockerfile that builds the application container should be hosted in its own repository in a trusted organization.
    • Secure your repository by implementing Mozilla's GitHub security standard.
  • Sign all release tags, and ideally commits as well
    • Developers should configure git to sign all tags and upload their PGP fingerprint to https://login.mozilla.com
    • The signature verification will eventually become a requirement to shipping a release to staging & prod: the tag being deployed in the pipeline must have a matching tag in git signed by a project owner. This control is designed to reduce the risk of a 3rd party GitHub integration from compromising our source code.
  • enable security scanning of 3rd-party libraries and dependencies
    • For node.js, use npm audit with audit-filter to review and handle exceptions (see example in speech-proxy)
    • For Python, enable pyup security updates:
      • Add a pyup config to your repo (example config: https://github.com/mozilla-services/antenna/blob/master/.pyup.yml)
      • Enable branch protection for master and other development branches. Make sure the approved-mozilla-pyup-configuration team CANNOT push to those branches.
      • From the "add a team" dropdown for your repo /settings page
        • Add the "Approved Mozilla PyUp Configuration" team for your github org (e.g. for mozilla and mozilla-services)
        • Grant it write permission so it can make pull requests
      • notify secops@mozilla.com to enable the integration in pyup
  • Keep 3rd-party libraries up to date (in addition to the security updates)
  • Integrate static code analysis in CI, and avoid merging code with issues
    • Javascript applications should use ESLint with the Mozilla ruleset
    • Python applications should use Bandit
    • Go applications should use the Go Meta Linter
    • Use whitelisting mechanisms in these tools to deal with false positives

Dual Sign Off

  • Services that push data to Firefox clients must require a dual sign off on every change, implemented in their admin panels
    • This mechanism must be reviewed and approved by the Firefox Operations Security team before being enabled in production

Logging

  • 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 level

Web Applications

  • Must have a CSP with
    • a report-uri pointing to the service's own /__cspreport__ endpoint
    • web API responses should return default-src 'none'; frame-ancestors 'none'; base-uri 'none'; report-uri /__cspreport__ to disallowing all content rendering, framing, and report violations
    • if default-src is not none, frame-src, and object-src should be none or only allow specific origins
    • no use of unsafe-inline or unsafe-eval in script-src, style-src, and img-src
  • Third-party javascript must be pinned to specific versions using Subresource Integrity (SRI)
  • Web APIs must set a non-HTML content-type on all responses, including 300s, 400s and 500s
  • Set the Secure and HTTPOnly flags on Cookies, and use sensible Expiration
  • Make sure your application gets an A+ on the Mozilla Observatory
  • Verify your application doesn't have any failures on the Security Baseline.
    • Contact secops@ or ping 'psiinon' on github to document exceptions to the baseline, mark csrf exempt forms, etc.
  • Web APIs should export an OpenAPI (Swagger) to facilitate automated vulnerability tests

Security 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 review
    • Store 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 and the SameSite attribute set to 'strict' or 'lax' (which allows external regular links to login).
    • For more information about potential pitfalls see the OWASP Session Management Cheat Sheet
  • Form that change state should use anti CSRF tokens. Anti CSRF tokens can be dropped for internal sites using SameSite session cookies where we are sure all users will be on Firefox 60+. Forms that do not change state (e.g. search forms) should use the 'data-no-csrf' form attribute.
  • Access 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.
  • If you are building a core Firefox service, consider adding it to the list of restricted domains in the preference extensions.webextensions.restrictedDomains. This will prevent a malicious extension from being able to steal sensitive information from it, see bug 1415644.

Databases

  • All SQL queries must be parameterized, not concatenated
  • Applications must use accounts with limited GRANTS when connecting to databases
    • In particular, applications must not use admin or owner accounts, to decrease the impact of a sql injection vulnerability.

Common issues

  • User data must be escaped for the right context prior to reflecting it
    • When inserting user generated html into an html context:
      • Python applications should use Bleach
      • Javascript applications should use DOMPurify
  • Apply sensible limits to user inputs, see input validation
    • POST body size should be small (<500kB) unless explicitly needed
  • When allowing users to upload or generate content, make sure to host that content on a separate domain (eg. firefoxusercontent.com, etc.). This will prevent malicious content from having access to storage and cookies from the origin.
    • Also use this technique to host rich content you can't protect with a CSP, such as metrics reports, wiki pages, etc.
  • When managing permissions, make sure access controls are enforced server-side
  • If an authenticated user accesses protected resource, make sure the pages with those resource arent cached and served up to unauthenticated users (like via a CDN).
  • If handling cryptographic keys, must have a mechanism to handle quarterly key rotations
    • Keys used to sign sessions don't need a rotation mechanism if destroying all sessions is acceptable in case of emergency.
  • Do not proxy requests from users without strong limitations and filtering (see Pocket UserData vulnerability). Don't proxy requests to link local, loopback, or private networks or DNS that resolves to addresses in those ranges (i.e. 169.254.0.0/16, 127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 172.16.0.0/12, 192.168.0.0/16, 198.18.0.0/15).
  • Do not use target="_blank" in external links unless you also use rel="noopener noreferrer" (to prevent Reverse Tabnabbing)
@caitmuenster
Copy link
Contributor

@psiinon, I think we're good to close this out. Can you confirm? :)

@psiinon
Copy link
Contributor

psiinon commented Feb 12, 2019

@caitmuenster its looking pretty good :)
Just a couple of outstanding issues:

  • @bqbn no CSP report-uri set - is this something you can add?
  • @bqbn none of the release tags seem to be signed - can you sign future ones?

Updated to ping the right person, sorry about that Bob :/

@bqbn
Copy link
Collaborator

bqbn commented Feb 12, 2019

no CSP report-uri set - is this something you can add?

@psiinon does static sites must have "report-uri" per secops standard?

Current Ops model for hosting a static website only contains cloudfront, edge lambda and s3 components. "report-uri" means that we very likely need to introduce an ELB and EC2 instances just to host the "report-uri" endpoint. It then requires logging, monitoring and etc.

That said, we can add it if it's a hard requirement, and we'd like to skip setting it if it's not mandatory.

none of the release tags seem to be signed - can you sign future ones?

We haven't cut any official release tags yet. Existing ones are for testing deployments only and can be removed in a later time.

Future official releases should be signed by whoever releases them.

@muffinresearch
Copy link
Contributor

@psiinon I don't know that we're signing releases for libs elsewhere in every case - is that a hard requirement?

I'd expect most releases will be done by cutting tags via the github UI. Even if that means it's signed because github creates that tag it does also mean anyone with write perms can release.

@psiinon
Copy link
Contributor

psiinon commented Feb 18, 2019

@bqbn I'd have thought we'd want a report-uri defined in case the CSP breaks something. Tbh thats more of a development concern than a security one.

@hwine how hard a requirement is signing releases on github?

@bqbn
Copy link
Collaborator

bqbn commented Feb 18, 2019

@psiinon thx for the clarification. I'm OK without report-uri then (from Ops perspective). @muffinresearch let me know if you think we need one from dev perspective.

Nevertheless, it doesn't sound like "report-uri" is a blocking factor for the release, e.g. we can file a bugzilla to add it if we decide to have it in the future. Also our other static site extensionschallenge.com doesn't have it.

@hwine
Copy link

hwine commented Feb 18, 2019

@psiinon signing (commit, tag, release) is only a recommended action at this time. There are a number of pitfalls in using signing, and extra tooling needed to support it.

I'm happy to take suggestions on how to better reflect that in the "docs".

@muffinresearch
Copy link
Contributor

@psiinon is there anything else from a security perspective that needs addressing before this issue can be closed out?

@psiinon
Copy link
Contributor

psiinon commented Mar 27, 2019

@muffinresearch I'm good with closing this out now :)

@caitmuenster
Copy link
Contributor

Thanks, @psiinon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Anything that has an impact on security
Projects
None yet
Development

No branches or pull requests

6 participants