fxa/packages/fxa-customs-server
Lauren Zugai 02c19ef4b4
Merge pull request #14652 from mozilla/train-247
Release 1.247.4 -> main
2022-12-19 15:31:37 -06:00
..
.vscode feat: add vscode tasks for running tests and debugger 2019-10-01 17:27:41 -07:00
bin task(customs): Add tracing to customs server 2022-09-19 13:33:46 -07:00
config chore(style): added prettier to fxa-customs-server 2019-06-25 09:36:41 -07:00
docs fix(customs): Revise Swagger docs in customs-server 2022-07-25 14:39:50 -04:00
grunttasks chore(format): mass reformat with prettier 2 and single config 2020-05-24 10:51:57 -07:00
lib task(customs): Add tracing to customs server 2022-09-19 13:33:46 -07:00
scripts chore(deps): switch from git to https for deps (#11587) 2022-01-11 16:28:42 -06:00
test maintenance(all) - Prepare for new sentry 2022-03-30 09:58:58 -07:00
.awsbox.json Actually address the typo that Andy found 2014-06-27 15:05:27 +12:00
.eslintrc docs(customs): Implement Swagger for API documentation 2022-07-18 18:33:43 -04:00
.nsprc fix(deps): Add exception for yargs-parser nsp advisory 1500 2020-05-11 11:40:27 -07:00
.prettierignore chore(style): added prettier to fxa-customs-server 2019-06-25 09:36:41 -07:00
CHANGELOG.md Merge pull request #13572 from mozilla/FXA-5496-stop-generating-changelogs-in-our-release-script 2022-07-11 16:20:36 -07:00
CONTRIBUTING.md chore(docs): Replace 'master' with 'main' throughout 2020-06-25 13:44:28 -07:00
Gruntfile.js chore(format): mass reformat with prettier 2 and single config 2020-05-24 10:51:57 -07:00
LICENSE Add a copy of the MPL and put tests in Public Domain 2014-05-06 16:28:34 +12:00
README.md chore(docs): Replace 'master' with 'main' throughout 2020-06-25 13:44:28 -07:00
package.json Merge pull request #14652 from mozilla/train-247 2022-12-19 15:31:37 -06:00
pm2.config.js task(customs): Add tracing to customs server 2022-09-19 13:33:46 -07:00

README.md

Firefox Accounts Customs Server

This project is used by the Firefox Accounts Auth Server to detect and deter fraud and abuse.

Development

To start the server, run:

npm start

It will listen on http://localhost:7000 by default.

Docker Based Development

To run the customs server via Docker:

$ docker-compose up mozilla/fxa_customs_server

Testing

Run tests with:

npm test

To run tests via Docker:

docker-compose run mozilla/fxa_customs_server npm test

Code

Here are the main components of this project:

  • ./bin/customs_server.js: process listening on the network and responding to HTTP API calls
  • ./lib/bans/: code implementing temporary bans of specific email or IP addresses and listening on the SQS API for requests
  • ./lib/config/config.js: where all of the configuration options are defined
  • ./lib/email_record.js, ./lib/ip_email_record.js and ./lib/ip_record.js: code implementing the various blocking and rate-limiting policies
  • ./scripts: helper scripts only used for development/testing
  • ./test/local: unit tests
  • ./test/remote: tests exercising the HTTP API

API

See our detailed API spec.

Policies

There are two types of policies:

  • rate-limiting: slows down attackers by temporarily blocking requests for 15 minutes (see config.limits.rateLimitIntervalSeconds)
  • block / ban: stops attacks by temporarily blocking requests for 24 hours (see config.limits.blockIntervalSeconds)

We currently have the following policies in place:

  • rate-limiting when too many emails (config.limits.maxEmails defaults to 3) have been sent to the same email address in a given time period (config.limits.rateLimitIntervalSeconds defaults to 15 minutes)
  • rate-limiting when too many requests to look up account status by email address (config.limits.maxAccountStatusCheck) have been sent from the same ip address during
  • rate-limiting when too many sms (config.limits.smsRateLimit.maxSms) have been sent from the same ip address during period (config.limits.smsRateLimit.limitIntervalSeconds defaults to 60 minutes)
  • rate-limiting when too many sms (config.limits.smsRateLimit.maxSms) have been sent from the same email address during period (config.limits.smsRateLimit.limitIntervalSeconds defaults to 60 minutes)
  • rate-limiting when too many sms (config.limits.smsRateLimit.maxSms) have been sent to the same phone number during period (config.limits.smsRateLimit.limitIntervalSeconds defaults to 60 minutes)
  • rate-limiting when too many failed login attempts (config.limits.maxBadLogins defaults to 2) have occurred for a given account and IP address, in a given time period (config.limits.rateLimitIntervalSeconds defaults to 15 minutes)
  • rate-limiting too many attempts to verify randomly-generated codes (config.limits.maxVerifyCodes defaults to 10) have occurred for a given account and IP address, in a given time period (config.limits.rateLimitIntervalSeconds defaults to 15 minutes)
  • manual blocking of an account (see /blockEmail API call)
  • manual blocking of an IP address (see /blockIp API call)

The data that these policies are based on is stored in a memcache instance (keyed by email, ip or ip + email depending on the policy) and the code that implements them is split across these three files:

  • email_record.js handles blocking and rate-limiting based only on the email address
  • ip_email_record.js handles rate-limiting based on both the email and IP address of the request
  • ip_record.js handles blocking based only on the IP address

The rate-limiting and blocking policies are conveyed to the auth server via the block property in the response to /check.