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 for payments server #1128

Closed
40 of 47 tasks
ianb opened this issue May 16, 2019 · 11 comments
Closed
40 of 47 tasks

Security checklist for payments server #1128

ianb opened this issue May 16, 2019 · 11 comments
Assignees

Comments

@ianb
Copy link
Contributor

ianb commented May 16, 2019

Risk Management

  • The service must have performed a Rapid Risk Assessment and have a Risk Record bug
  • [todo: Julien] 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
    • [bug] 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.
  • Correctly set client IP
    • Confirm client ip is in the proper location in X-Forwarded-For, modifying what is sent from the client if needed. AWS and GCP's load balancers will do this automatically.
    • Make sure the web server and the application get the true client IP by configuring trusted IP's within Nginx or Apache
    • If you have a service-oriented architecture, you must always be able to find the IP of the client that sent the initial request. We recommend passing along the X-Forwarded-For to all back-end services.
  • 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
  • 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

  • Assigned to @LZoog (issue Add CSP to the payments-server #1923) 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)
    • We use third-party JS from Stripe and they do not support SRI. Their JS can and will change on a schedule not in sync with our deployments. However, one of the main reasons payments-server exists as a separate RP at a separate origin from the rest of FxA is in part to isolate this third-party JS.
  • 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
    • We might not get to an A+, considering that we may not be able to implement SRI. We should address CSP, HSTS, and Referer Policy though.
  • 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
  • When using cookies for session management, make sure you have CSRF protections in place, which in 99% of cases is SameSite cookies. If you can't use SameSite, use anti CSRF tokens. There are two exceptions to implementing CSRF protection:
    • Forms that don't change state (e.g. search forms) don't need CSRF protection and can indicate that by setting the 'data-no-csrf' form attribute (this tells our ZAP scanner to ignore those forms when testing for CSRF).
    • Sites that don't use cookies for anything sensitive can ignore CSRF protection. A lot of modern sites prefer to use local-storage JWTs for session management, which aren't vulnerable to CSRF (but must have a rock solid CSP).
  • 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)

(This is a copy of the checklist from #741)

@clouserw
Copy link
Member

Once we're in production, we'll start checking off this list.

@clouserw clouserw added this to the Train 139 milestone May 20, 2019
@clouserw
Copy link
Member

@jbuck once you have the deploys done, can you hit the ops stuff on this list? Thank you

@clouserw clouserw modified the milestones: Train 139, Train 140 Jun 10, 2019
@clouserw clouserw modified the milestones: Train 140, Train 141 Jun 24, 2019
@clouserw clouserw modified the milestones: Train 141, Train 142 Jul 8, 2019
jaredhirsch added a commit to jaredhirsch/fxa that referenced this issue Jul 22, 2019
jaredhirsch added a commit to jaredhirsch/fxa that referenced this issue Jul 22, 2019
* audit-filter claims it removed 17312 vulnerabilities by removing 2 packages
  and updating 4 packages.

Related to issue mozilla#1128
jaredhirsch added a commit to jaredhirsch/fxa that referenced this issue Jul 22, 2019
jaredhirsch added a commit to jaredhirsch/fxa that referenced this issue Jul 22, 2019
* audit-filter claims it removed 17312 vulnerabilities by removing 2 packages
  and updating 4 packages.

Related to issue mozilla#1128
@jaredhirsch
Copy link
Member

@jvehent Hey, I've done a first pass through some of the dev items on this list, while some of the others don't really apply, and yet others will take some work. Are there any items that are higher priority, and which we'd definitely want to finish up before an initial release of the payments / subscription server?

@chenba
Copy link
Contributor

chenba commented Jul 29, 2019

The value for HSTS max-age is 15552000 across all the FxA packages. It's also the currently value in prod accounts.firefox.com. It's easy to update it for the payments server, but the inconsistency is going to make me sad.

chenba added a commit to chenba/fxa that referenced this issue Jul 30, 2019
Update HSTS to the value asked on the Security Checklist.

Part of mozilla#1128
chenba added a commit to chenba/fxa that referenced this issue Jul 30, 2019
Update HSTS to the value asked on the Security Checklist.

Part of mozilla#1128

reorder props
@ianb ianb removed their assignment Aug 5, 2019
@jvehent
Copy link

jvehent commented Sep 3, 2019

@jrgm What are the URLs for staging and production? I'd like to update our metadata.

@jvehent
Copy link

jvehent commented Sep 27, 2019

Remaining issues:

  • Opened bug to add subscriptions.firefox.com to the preloaded pins of firefox. this isn't a blocker.
  • HSTS is in place but observatory complains about it because, well, the site returns 3 HSTS headers... one would be sufficient :)
  • CSP allows unsafe-inline scripts, that should get removed.

@clouserw
Copy link
Member

Thanks @jvehent . I filed #2649 and #2650 to track those last two and will close this giant list. 👍

@LZoog
Copy link
Contributor

LZoog commented Sep 27, 2019

#2649 is a dupe of #2138 (adding this comment for reference).

@jaredhirsch
Copy link
Member

jaredhirsch commented Sep 27, 2019

#2650 appears to be a bug in observatory. HSTS headers are concatenated by observatory when a redirect occurs, and the redirect flow is subscriptions.f.c -> accounts.f.c/settings -> accounts.f.c/signin. Each of these has a single HSTS header, based on what devtools network tab reports.

I'll file a bug against observatory and link it to #2650.

@jvehent
Copy link

jvehent commented Sep 27, 2019

I'm not sure this is a bug in observatory. curl returns the same results:

$ curl -si https://subscriptions.firefox.com/ |grep strict-transport-security
strict-transport-security: max-age=31536000; includeSubDomains
strict-transport-security: max-age=31536000
strict-transport-security: max-age=31536000

@jaredhirsch
Copy link
Member

@jvehent Yup, thanks. I was just puzzling over a number of repeated headers in the raw curl output, digging in the curl manual to make sure I wasn't missing an argument

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

No branches or pull requests

8 participants