Firefox Monitor arms you with tools to keep your personal information safe. Find out what hackers already know about you and learn how to stay a step ahead of them.
Перейти к файлу
Vincent be7fd80e2c Apply Prettier to checkNodeVersionAlignment
Now that it's inside /src/, Prettier thinks it's relevant.
2024-08-19 12:54:48 +01:00
.github Remove /scripts/ directory 2024-08-19 12:54:48 +01:00
.husky Remove deprecated Husky call 2024-08-01 11:15:41 +00:00
.storybook fix: Add missing dev dependency @storybook/addon-actions 2024-05-22 17:14:46 +02:00
.vscode Refine setup for VSCode users 2024-01-19 18:52:47 +01:00
config chore: Update Monitor CTA experiment copy 2024-07-23 12:30:24 +02:00
docs Update docs on react-intersection-observer testing 2024-08-07 16:27:04 +02:00
locales Import translations from l10n repository (2024-08-18) 2024-08-19 08:01:45 +01:00
locales-pending Avoid people thinking 14 days fixes *all* scan results 2024-07-24 12:45:38 +02:00
public Use solid background colour for logo in dark mode 2024-08-07 16:03:06 +02:00
src Apply Prettier to checkNodeVersionAlignment 2024-08-19 12:54:48 +01:00
.dockerignore Removes version.json from the .dockerignore file. 2018-06-08 16:21:54 -04:00
.env merge: main -> mntor-3394 2024-07-23 18:24:27 +02:00
.env.local.example merge: main -> mntor-3394 2024-07-23 18:24:27 +02:00
.eslintignore Remove dynamic NEXT_PUBLIC_* environment variables 2023-11-13 10:11:27 +01:00
.eslintrc.json chore: Delete pre-redesign client directory and esbuild 2024-03-13 17:29:39 +01:00
.git-blame-ignore-revs Add commit 9cf79b6 to .git-blame-ignore-revs 2023-06-20 18:42:41 +02:00
.gitignore Adopt .env.local file 2024-07-09 10:58:25 +02:00
.lintstagedrc.js chore: Don’t scope prettier write command to src/app only 2024-03-14 13:25:43 +01:00
.prettierignore chore: Delete pre-redesign client images 2024-03-14 12:43:32 +01:00
.prettierrc.json Merge Next.js into `main` (#3116) 2023-06-12 13:35:35 -07:00
.stylelintrc Block the use of !important in our CSS 2024-05-02 15:41:59 +02:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file 2019-03-30 00:10:15 -07:00
Dockerfile chore(deps): bump node from 22.4-alpine to 22.5-alpine 2024-07-22 15:55:34 +00:00
Dockerfile.cloudrun chore(deps): bump node from 22.4-alpine to 22.5-alpine 2024-07-22 15:55:34 +00:00
LICENSE Add LICENSE file and update package.json license 2018-06-07 14:49:16 -07:00
Procfile Migrate the database on deploy 2022-08-23 10:28:18 -05:00
README.md Update dependency doc with info on testing backend updates (#4919) 2024-08-06 11:49:55 -07:00
catalog-info.yaml ci: get rid of circle CI 2024-05-17 10:02:38 -07:00
esbuild.cronjobs.js feat: update 22.4 to 22.5 2024-07-22 09:02:12 -07:00
jest.config.cjs Explicitly set up IntersectionObserver mocking 2024-08-05 14:45:21 +00:00
jest.setup.ts Explicitly set up IntersectionObserver mocking 2024-08-05 14:45:21 +00:00
l10n.toml Update l10n linter to moz-l10n-lint 2019-05-09 15:20:06 -07:00
locationAutocompleteData.json chore: Include less info per location to reduce filesize 2024-02-07 11:58:06 +01:00
netlify.toml feat: update 22.4 to 22.5 2024-07-22 09:02:12 -07:00
next-env.d.ts Merge Next.js into `main` (#3116) 2023-06-12 13:35:35 -07:00
next.config.js Update next.config.js 2024-05-15 06:55:42 -07:00
package-lock.json chore(deps-dev): bump the storybook group across 1 directory with 9 updates 2024-08-19 07:47:02 +00:00
package.json chore(deps-dev): bump the storybook group across 1 directory with 9 updates 2024-08-19 07:47:02 +00:00
playwright.config.js Adopt .env.local file 2024-07-09 10:58:25 +02:00
requirements.txt MNTOR-2022/re-land glean.js (#3413) 2023-09-14 18:41:36 -07:00
sentry.client.config.ts ran npx @sentry/migr8@latest per the Sentry release notes 2024-05-13 19:39:43 -07:00
tsconfig.cronjobs.json Add a cron job for the monthly activity email 2024-04-29 09:48:28 -05:00
tsconfig.json Remove some more unused code and dependencies 2024-03-26 09:38:18 +01:00

README.md

Firefox Monitor Server

Summary

Firefox Monitor notifies users when their credentials have been compromised in a data breach.

This code is for the monitor.mozilla.org service & website.

Breach data is powered by haveibeenpwned.com.

See the Have I Been Pwned about page for the "what" and "why" of data breach alerts.

Architecture

Image of Monitor architecture

Development

Requirements

Code style

Linting and formatting is enforced via ESLint and Stylelint for JS and CSS. Both are installed as dev-dependencies and can be run with npm run lint. A push to origin will also trigger linting.

ESLint rules are based on eslint-config-standard. To fix all auto-fixable problems, run npx eslint . --fix

Stylelint rules are based on stylelint-config-standard. To fix all auto-fixable problems, run npx stylelint public/css/ --fix

GIT

We track commits that are largely style/formatting via .git-blame-ignore-revs. This allows Git Blame to ignore the format commit author and show the original code author. In order to enable this in GitLens, add the following to VS Code settings.json:

"gitlens.advanced.blame.customArguments": [
   "--ignore-revs-file",
   ".git-blame-ignore-revs"
],

Database

To create the database tables ...

  1. Create the blurts database:

    createdb blurts
    createdb test-blurts # for tests
    
  2. Update the DATABASE_URL value in your .env.local (see step 3 under "Install") file with your local db credentials:

    DATABASE_URL="postgres://<username>:<password>@localhost:<port>/blurts"
    
  3. Run the migrations:

    npm run db:migrate
    

Install

  1. Clone and change to the directory:

    git clone https://github.com/mozilla/blurts-server.git
    cd blurts-server
    
  2. Install dependencies:

    npm install
    
  3. Copy the .env.local.example file to .env.local:

    cp .env.local.example .env.local
    
  4. Install fluent linter (requires Python)

    pip install -r .github/requirements.txt
    
    OR
    
    pip3 install -r .github/requirements.txt
    
  5. Generate required Glean files (needs re-ran anytime Glean .yaml files are updated):

    npm run build-glean
    
  6. Generate required Nimbus files (needs re-ran anytime Nimbus' config/nimbus.yaml file is updated):

    npm run build-nimbus
    
  7. Create location data: Running the script manually is only needed for local development. The location data is being used in the onboarding exposures scan for autocompleting the “City and state” input.

    npm run create-location-data
    
  8. Ensure that you have the right env variables/keys set in your .env.local file. You can retrieve the variables from the Firefox Monitor 1Password Vault, or through Magic-Wormhole, by asking one of the our engineers.

Run

  1. To run the server similar to production using a build phase, which includes minified and bundled assets:

    npm start
    

    OR

    Run in "dev mode" with:

    npm run dev
    
  2. You may receive the error Required environment variable was not set. If this is the case, get the required env var(s) from another team member or ask in #fx-monitor-engineering. Otherwise, if the server started successfully, navigate to localhost:6060

PubSub

Monitor uses GCP PubSub for processing incoming breach data, this can be tested locally using an emulator: https://cloud.google.com/pubsub/docs/emulator

Run the GCP PubSub emulator:

gcloud beta emulators pubsub start --project=your-project-name

(Set your-project-name as the value for GCP_PUBSUB_PROJECT_ID in your .env.local.)

In a different shell, set the environment to point at the emulator and run Monitor in dev mode:

$(gcloud beta emulators pubsub env-init)
npm run dev

Incoming WebHook requests from HIBP will be of the form:

curl -d '{ "breachName": "000webhost", "hashPrefix": "test", "hashSuffixes": ["test"] }' \
  -H "Authorization: Bearer unsafe-default-token-for-dev" \
  http://localhost:6060/api/v1/hibp/notify

This emulates HIBP notifying our API that a new breach was found. Our API will then add it to the (emulated) pubsub queue.

This pubsub queue will be consumed by this cron job, which is responsible for looking up and emailing impacted users:

NODE_ENV="development" npm run dev:cron:breach-alerts

Emails

Monitor generates multiple emails that get sent to subscribers. To preview or test-send these emails see documentation here.

Mozilla accounts ("FxA", formerly known as Firefox accounts)

The repo comes with a development FxA oauth app pre-configured in .env, which should work fine running the app on http://localhost:6060. You'll need to get the OAUTH_CLIENT_SECRET value from a team member or someone in #fxmonitor-engineering.

Testing

The unit test suite can be run via npm test.

At the beginning of a test suite run, the test-blurts database will be populated with test tables and seed data found in src/db/seeds/

At the end of a test suite, coverage info will be sent to Coveralls to assess coverage changes and provide a neat badge. To upload coverage locally, you need a root .coveralls.yml which contains a token – get this from another member of the Monitor team.

End-to-End tests use Playwright and can be run via npm run e2e. E2E-How-To for more info.

Test Firefox Integration

TODO: the following functionality is disabled but the instructions are left here for posterity.

Firefox's internal about:protections page ("Protections Dashboard") fetches and displays breach stats for Firefox users who are signed into their FXA.

To test this part of Monitor:

  1. Set a Firefox profile to use the staging Firefox Accounts server.
  2. In the same profile, go to about:config and replace all https://monitor.firefox.com values with http://localhost:6060
  3. Restart Firefox with that profile.
  4. Go to about:protections
  5. Everything should be using your localhost instance of Monitor.

Load testing

k6 is used for load testing.

To test the HIBP breach alerts endpoint, use:

export SERVER_URL=...
export HIBP_NOTIFY_TOKEN=...
k6 -u 10 src/scripts/loadtest/hibp.js # Run with 10 virtual users

See https://grafana.com/docs/k6/latest/get-started/running-k6/ for more information.

Localization

All text that is visible to the user is defined in Fluent files inside /locales/en/ and /locales-pending/. After strings get added to files in the former directory on our main branch, they will be made available to our volunteer localizers via Pontoon, Mozilla's localization platform. Be sure to reference the localization documentation for best practices. It's best to only move the strings to /locales/en/ when they are more-or-less final and ready for localization. Your PR should be automatically tagged with a reviewer from the Mozilla L10n team to approve your request.

You can check translation status via the Pontoon site. After strings have been localized, a pull request with the updated strings is automatically opened against our repository. Please be mindful that Mozilla localizers are volunteers, and translations come from different locales at different times – usually after a week or more.

To use the strings in code, you need to obtain a ReactLocalization instance, which selects the right version of your desired string for the user. How to do that depends on where your code runs: in tests, in a cron job, in a server component, or on the client-side. Generally, you will import a getL10n function from one of the modules in /src/app/functions/l10n/, except for Client Components, which use the useL10n hook. Look at existing code for inspiration.

Preview Deployment

We use GCP Cloudrun for dev review – official stage and production apps are built by the Dockerfile and Github Actions. Everything that is merged into main will deploy automatically to stage. The ADR for preview deployment can be found here

TODO: add full deploy process similar to Relay

TODO: consider whether we can re-enable Heroku Review Apps