# Business edition service

The Business edition adds a hosted console: connected computers send their report about every six hours, the console shows all computers of a company in one place, and alerts go out by email. It runs on [Supabase](https://supabase.com) (database, sign-in and two small functions) plus any static web host for the console page.

```
extension ──report + company key──▶ ingest-report function ──▶ database (reports, alerts)
                                                                   ▲
console page ──sign in by email link──▶ Supabase Auth ──read own company only (row-level security)
daily scheduled job ──▶ check-stale function ──▶ alerts for computers that stopped reporting
```

| Part | Where |
| --- | --- |
| Database tables, access rules and functions | `supabase/migrations/20261004000000_business.sql` |
| Report collection | `supabase/functions/ingest-report/` (logic in `_shared/ingest.js`) |
| Daily check for silent computers | `supabase/functions/check-stale/` (logic in `_shared/stale.js`) |
| Alert rules and email | `supabase/functions/_shared/alerts.js` |
| Confirming alert addresses | `supabase/functions/alert-recipients/` (logic in `_shared/alert-recipients.js`), `supabase/migrations/20261011000000_alert_safety.sql` |
| Console page | `service/web/`, built into `dist/step1-cloud/index.html` |
| Step 2 readiness check | `service/web/readiness.js` (questions, score, vendor shortlist), `supabase/migrations/20261005000000_readiness.sql` |
| Known dangerous sites (Business Plus) | `supabase/functions/threat-intel/` (logic in `_shared/threat-intel.js`), `supabase/migrations/20261006000000_threat_intel.sql`; extension side in `src/shared/threat-list.js` |
| Monthly compliance reports (Business Plus) | `service/web/compliance.js` (daily summaries, report and evidence mapping), `service/web/report-view.js`, `supabase/migrations/20261007000000_compliance_history.sql` |
| Policy groups | `service/web/policy-form.js`, `service/web/policies-view.js`, `supabase/functions/device-policy/` (logic in `_shared/device-policy.js`), `supabase/migrations/20261008000000_policy_groups.sql` |
| Public domain check | `service/web/domain-check.js` (findings and score), `service/web/domain-view.js`, `supabase/functions/domain-check/` (logic in `_shared/domain-scan.js`), `supabase/migrations/20261009000000_domain_checks.sql` |
| Alert webhooks | `supabase/functions/_shared/alerts.js` (delivery and signing), `supabase/migrations/20261014000000_webhooks.sql` |
| Languages | the company's email language (`companies.language`, Settings in the console) and translatable alerts (`alerts.i18n`): `supabase/migrations/20261017000000_company_language.sql`; email texts in `src/i18n/email/`, copied to `_shared/email-text/` by `npm run build:service`. Apply this migration before deploying the 0.30 console, which reads the new column. |
| Tools for IT partners (co-branding per company sent with the console policy, ticket mailboxes with one email per alert, billing CSV) | `supabase/migrations/20261018000000_msp_tools.sql`; `service/web/billing.js`; the Branding section and ticket checkboxes in `service/web/cloud.js`. Apply this migration before deploying the 0.32 console, which reads the new `branding` and `ticket` columns. |
| Teams and MSPs (invites, roles, many companies) | `supabase/migrations/20261015000000_partners.sql`; console People section and All companies tab in `service/web/cloud.js` |
| Website categories (Business Plus) | `supabase/functions/category-update/` and `category-list/` (logic in `_shared/category-update.js`, `_shared/category-stream.js` and `_shared/category-list.js`), `supabase/migrations/20261016000000_categories.sql`, `20261022000000_category_checked.sql` and `20261023000000_category_parts.sql`; extension side in `src/shared/categories.js` and `src/shared/bloom.js` |
| Requests for access and app review (0.37) | `supabase/functions/access-request/` (logic in `_shared/access-request.js`), `supabase/migrations/20261019000000_access_requests.sql`; console Requests tab in `service/web/access-view.js`; extension side in `src/shared/access.js`, `src/background/access.js`, `src/pages/blocked-extras.js` and `src/shared/company-lists.js`. Apply this migration before deploying the 0.37 console, which reads the new tables. |
| Known malware in downloads (0.40) | `supabase/functions/file-check/` (logic in `_shared/file-check.js`), `supabase/migrations/20261021000000_file_check.sql`; extension side in `src/shared/malware-check.js` and `src/background/malware-check.js`. Computers send only a downloaded file's SHA-256; the function looks it up in abuse.ch MalwareBazaar with the `MALWAREBAZAAR_AUTH_KEY` secret (step 4). |
| Extension side | "Connect to your company" in setup; `src/shared/company.js`; sending in `src/background.js` |

## How access works

- People sign in with an emailed link. They see only companies they belong to: every table has row-level security, and they cannot write to tables directly, so they cannot change their own plan or trial date.
- Computers never sign in. They send reports with a **company key** created in the console. Only a SHA-256 hash of the key is stored; it is shown once and can be revoked.
- Only the two functions use the **service role key**, which bypasses row-level security. It must never go into the console page or the extension.
- Reports never contain the company key, pasted text, file contents or page addresses (see the privacy notes in the main README).

## Deploy, step by step

You need a computer with Node.js 20 or later and this repository.

### 1. Create the Supabase project

1. Sign up at supabase.com and create a project. Choose an EU region (for example Frankfurt) if your customers are in the EU.
2. In **Project Settings → API**, note the **Project URL**, the **anon public** key and the **service_role** key. The service role key is secret.

### 2. Put the database in place

```bash
npx supabase login
npx supabase link --project-ref <your-project-ref>   # the part before .supabase.co
npx supabase db push                                  # runs the migration
```

### 3. Set up sign-in

In **Authentication → URL Configuration**, set **Site URL** to the address where you will host the console (step 6), for example `https://console.yourcompany.com`, and add the same address under **Redirect URLs**.

Supabase's built-in email is meant for testing and sends only a few emails per hour. Before real customers sign in, connect your own email provider under **Authentication → Emails → SMTP Settings**.

### 4. Set the function secrets and deploy the functions

Alert emails are sent through [Resend](https://resend.com). Create an account, verify your sending domain and create an API key. Then:

```bash
npx supabase secrets set \
  RESEND_API_KEY=re_xxxxxxxx \
  ALERT_FROM_EMAIL="Step 1 alerts <alerts@yourcompany.com>" \
  CONSOLE_URL=https://console.yourcompany.com \
  CRON_SECRET=$(openssl rand -hex 32) \
  ADVISOR_EMAIL=advisor@yourcompany.com

npx supabase functions deploy ingest-report
npx supabase functions deploy check-stale
npx supabase functions deploy threat-intel
npx supabase functions deploy device-policy
npx supabase functions deploy domain-check
npx supabase functions deploy alert-recipients
npx supabase functions deploy category-list
npx supabase functions deploy category-update
npx supabase functions deploy access-request
npx supabase functions deploy file-check
```

The known-malware check in downloads asks abuse.ch MalwareBazaar. Get a free Auth-Key at
[auth.abuse.ch](https://auth.abuse.ch/) and set it as a secret; it stays on the server, never in
the extension or the console:

```bash
npx supabase secrets set MALWAREBAZAAR_AUTH_KEY=xxxxxxxx
```

Without it, `file-check` answers "not known" and downloads simply continue.

Supabase provides `SUPABASE_URL` and `SUPABASE_SERVICE_ROLE_KEY` to the functions itself. Without `RESEND_API_KEY`, alerts still appear in the console but no email is sent. Alerts are emailed only to confirmed addresses: a member's own sign-in address counts as confirmed, any other address on the alert list first gets a confirmation email (sent by `alert-recipients`, whose link opens the console at `CONSOLE_URL`, where its owner clicks to confirm). The confirmation tokens are made only by that function and appear only in the email. Limits: 20 alert emails a day per company, 20 confirmation emails a day per person, one confirmation email a day per address, and at most 1,000 computers per company that reported in the last 30 days (100 new ones a day). `ADVISOR_EMAIL` is where shared Step 2 readiness checks are emailed; leave it out until you are ready to follow up on them. Keep the `CRON_SECRET` value for the next step (`npx supabase secrets list` shows only a hash of it, so copy it when you create it).

### 5. Run the daily check

In **Database → Extensions**, turn on `pg_cron` and `pg_net`. Then run this once in the **SQL Editor**, with your project ref and `CRON_SECRET` filled in:

```sql
select cron.schedule('step1-check-stale', '0 6 * * *', $$
  select net.http_post(
    url := 'https://<your-project-ref>.supabase.co/functions/v1/check-stale',
    headers := jsonb_build_object('content-type', 'application/json', 'x-cron-secret', '<CRON_SECRET>'),
    body := '{}'::jsonb,
    timeout_milliseconds := 60000
  );
$$);
```

The wait of 60 seconds matters: without it the database waits 5, and a function that takes a few seconds to start (seen on 30 November 2026: 6 seconds) does its work but is recorded as timed out in `net._http_response`.

It runs every day at 06:00 UTC, emails about computers that have not reported for 7 days, deletes alerts older than 180 days, and emails `ADVISOR_EMAIL` about Step 2 readiness checks that were shared or updated since the day before.

For website categories (Business Plus), schedule the list builder the same way. It downloads the UT1 category lists (18 MB for the largest) and packs them into the filters the computers download, so give it a quiet hour:

```sql
select cron.schedule('step1-category-update', '30 5 * * *', $$
  select net.http_post(
    url := 'https://<your-project-ref>.supabase.co/functions/v1/category-update',
    headers := jsonb_build_object('content-type', 'application/json', 'x-cron-secret', '<CRON_SECRET>'),
    body := '{}'::jsonb,
    timeout_milliseconds := 300000
  );
$$);
```

Until it has run at least once, computers asking for a category list get "not ready" and simply try again the next day.

**The adult list** (an 18 MB archive with 4.6 million domains) is too much for one function call: a function may use 2 seconds of processing, and calls that run at the same time share them. So it is built once a week in steps, by a second scheduled job that calls `category-update` with `{"step": true}` every 10 minutes for two hours. Each call does one piece of work: one of three parts, kept in the table `category_list_parts`, and then the join that saves the list (ALGORITHMS.md section 11). Keep it away from the daily job's time, so the two never share a worker:

```sql
select cron.schedule('step1-category-parts', '*/10 3-4 * * *', $$
  select net.http_post(
    url := 'https://<your-project-ref>.supabase.co/functions/v1/category-update',
    headers := jsonb_build_object('content-type', 'application/json', 'x-cron-secret', '<CRON_SECRET>'),
    body := '{"step": true}'::jsonb,
    timeout_milliseconds := 300000
  );
$$);
```

Its answers read `part-1-of-3`, `part-2-of-3`, `part-3-of-3`, then the number of domains, and `not-due` for the rest of the week. Without this job the adult list is never built, and computers that block Adult keep getting "not ready". When updating an existing service, apply the migrations `20261022000000_category_checked.sql` and `20261023000000_category_parts.sql` before deploying the new `category-update`, and schedule this second job.

**Mind the bandwidth.** A computer downloads a chosen list only when it changed (since 0.48 a list rebuilt without changes keeps its date). The small lists are at most a few hundred kB. The adult list is about 9 MB and changes about once a week, so each computer that blocks adult sites downloads about 38 MB a month: about 38 GB a month for 1,000 such computers. Supabase counts this as egress: 5 GB a month on the Free plan, 250 GB on Pro, then USD 0.09 per GB (November 2026).

**Alert webhooks** need no extra secrets: a member sets the address under **Settings → Alert webhook** in the console, and the signing secret is created by the database and shown once. New alerts are then POSTed as JSON with an `x-step1-signature` header (`sha256=` + HMAC-SHA256 of the body with that secret). The delivery resolves the address through DNS-over-HTTPS, refuses private addresses and connects only to the checked address, like the domain check.

### 6. Build and host the console page

```bash
SUPABASE_URL=https://<your-project-ref>.supabase.co SUPABASE_ANON_KEY=<anon public key> npm run build:console
```

Upload `dist/step1-cloud/index.html` to any static host (Vercel, Netlify, Cloudflare Pages or similar) at the address you used in step 3. Upload the manuals site (`npm run build:manual`, the whole `dist/manual/` folder) next to it, as `manual/` one level up from the console page, so the console's **Help** link (`../manual/index.html`) works. The anon key is meant to be public; the database rules protect the data. Do not commit this configured build: run `npm run build:console` without the variables afterwards, so the committed file stays unconfigured.

### 7. Try it end to end

1. Open the console, sign in with your email and create a company. It gets a 30-day trial.
2. Under **Connect computers**, create a key.
3. In the extension, open **Change settings → Connect to your company**, enter the project URL and the key, and click **Test connection**.
4. Save. The computer sends its report straight away; it appears under **Overview** after a reload.
5. Switch data protection off in the extension and choose **Send report now** on its report page: an alert appears, and an email arrives if Resend is set up.

6. Open **Step 2**, answer the questions and choose **See my result**. Then share it with an advisor: the next daily run emails `ADVISOR_EMAIL`.

To connect many computers at once, push the two policy values shown after creating a key (`companyServiceUrl`, `companyEnrolmentKey`) with Intune, Group Policy or Google Admin.

## Running a customer

Billing is not built yet. Until it is, start a paid plan by hand in the **SQL Editor**:

```sql
update companies set plan = 'business', paid_until = now() + interval '1 year' where name = 'Acme B.V.';
```

When a trial or paid period ends, the service stops accepting reports (the extension shows "subscription not active") and the console says so; nothing is deleted.

## Known dangerous sites (Business Plus)

Computers of companies on the `business_plus` plan get phishing, malware and unwanted-software warnings from [Google Web Risk](https://cloud.google.com/web-risk). The `threat-intel` function holds your Google API key and does two things for them:

- **List updates** (free at Google): passes on Google's changes to the lists, which each computer keeps and checks every page against.
- **Confirmations** (paid at Google): when the first bytes of a page's hash match the list, the computer sends those bytes (never the address) and gets back the full hashes to compare. Google charges USD 0.05 per confirmation (October 2026; check [the pricing page](https://cloud.google.com/web-risk/pricing)).

To switch it on:

1. In the [Google Cloud console](https://console.cloud.google.com), create a project, turn on billing, enable the **Web Risk API** and create an API key. Restrict the key to the Web Risk API.
2. Set the key and your caps, then deploy:

   ```bash
   npx supabase secrets set \
     WEB_RISK_API_KEY=AIza... \
     THREAT_DAILY_CAP_PER_COMPANY=200 \
     THREAT_MONTHLY_CAP_PER_COMPANY=300 \
     THREAT_MONTHLY_CAP=2000
   npx supabase functions deploy threat-intel
   ```

3. Put a company on Business Plus: `update companies set plan = 'business_plus', paid_until = now() + interval '1 year' where name = 'Acme B.V.';`

**Cost control.** Answers are cached for every customer until Google says they expire, so a popular site that happens to share a hash prefix is paid for once. `THREAT_DAILY_CAP_PER_COMPANY` limits paid confirmations per company per day (default 200), `THREAT_MONTHLY_CAP_PER_COMPANY` per company per calendar month (default 300), and `THREAT_MONTHLY_CAP` for the whole service per calendar month (2,000 is USD 100). Raise the service cap as Business Plus customers are added, to about their number times the per-company cap, so one company cannot use up the budget of the others. Over a cap, confirmations stop for the rest of the day or month: those pages are not warned about, and the browser's own Safe Browsing still applies. The daily job deletes expired answers. To see this month's use:

```sql
select c.name, sum(u.calls) as confirmations from threat_search_usage u join companies c on c.id = u.company_id
where u.day >= date_trunc('month', now())::date group by c.name order by 2 desc;
```

My rough estimate is 5 to 10 confirmations per person per month before caching, so USD 0.25 to 0.50 (each computer keeps about 390,000 prefixes, so roughly one page in a thousand needs one), but measure it with the query above in a pilot before setting your Business Plus price.

**Google's conditions.** Warnings must use cautious wording, link to background information and say "Advisory provided by Google"; the extension's warning page does this. Read the [Web Risk terms](https://cloud.google.com/terms/service-terms) before selling it.

## Requests for access and app review

When Step 1 blocks a site or an app, the warning page lets people ask for access with a reason
from a short list. On a connected computer the request goes to the `access-request` function with
the company key; it holds the site's name, what blocked it, the reason and the computer's ID, never
the page address. Members answer on the console's **Requests** tab:

- **Let it through** puts the site on the company's allowed sites; **Approve the app** approves it
  in the app review. Computers get both within the hour with their console policy (or straight
  away when the person chooses **Check again** on the warning page), as the policy keys
  `companyAllowedSites`, `companyApprovedApps`, `companyAppsInReview` and `companyRefusedApps`.
  These add to each group's own settings instead of replacing them, and a group cannot set them.
- **App review**: every app in use (and every app reviewed before) can be set to not reviewed,
  being reviewed (it opens read-only), approved or not approved, for the whole company.
- **Limits**: 10 requests a day per computer, 200 open requests, 500 allowed sites and 500
  reviewed apps per company; answered requests are deleted after 90 days.
- **Deploy**: run the migration and `npx supabase functions deploy access-request`. It checks the
  company key itself, so `verify_jwt` is off in `supabase/config.toml`.

Without a company console, the warning page offers an email to the IT support address set in the
setup instead.

## Public domain check

The **Public domain check** on the Overview tab shows what a company's domain shows to the internet, the "external attack surface" part of the risk dashboards that large vendors sell.

- **What it reads:** DNS records through Cloudflare's public DNS-over-HTTPS (MX, SPF, DMARC, MTA-STS, DNSSEC); the status and security headers of `https://` and `http://` on the domain or `www.`; the newest certificate in public certificate logs (crt.sh). It reads no page content and scans no ports.
- **Safety:** names that point to private or reserved addresses are not fetched, redirects are only followed inside the same domain (at most two), responses are cut off after the headers, and certificate-log answers over 2 MB are dropped. Known gap: `fetch` looks the name up again itself, so a domain whose DNS changes answers between the two lookups could make the function send one GET to an internal address on port 80 or 443. Only the status and a few security headers would be used, and they are only stored as findings; an outgoing proxy that blocks private ranges would close it fully.
- **Limits:** members of an active company only; 20 checks a day and 5 domains per company, and 40 checks a day per person across companies (in `claim_domain_check`, which reserves the domain under a lock so parallel requests cannot pass the limit). Only the function writes results, so they cannot be faked from the console. A check that fails frees its place again.
- **Score:** each finding costs points (missing DMARC 25, missing SPF 20, and so on; see `service/web/domain-check.js`). The average over a company's domains is the **Exposure** part of the security score.
- **Deploy:** run the migration and `npx supabase functions deploy domain-check`. It uses the member's own sign-in, so `verify_jwt` stays on. It needs the `CONSOLE_URL` secret: only the console may call it from a browser, and without it the function answers that it is not set up.

## Policy groups

The **Policies** tab sets the extension's settings for groups of computers, using the same keys as the managed policy in `managed_schema.json`. Every key is in the form except those listed in `NOT_IN_FORM` (`service/web/policy-form.js`): the company connection, two old names, and the branding keys, which come from **Settings, Branding** instead.

- **Groups:** the first group a company creates is its default; every computer follows it until it is moved to another group in the **Computers** table. The default group cannot be deleted. Up to 50 groups per company.
- **How computers get it:** a connected computer asks the `device-policy` function every hour, with its company key and computer ID. The function returns the policy of its group. Settings left on "Not set" stay the person's own choice; the others are locked in the setup.
- **Groups by person (0.38):** a group can list people by work account (`policy_groups.accounts`, set with `set_group_accounts`, migration `20261020000000_person_groups.sql`). A computer that reports its browser's work account (the `reportWorkAccount` setting, and the person allowed it) sends it with its policy request and gets that person's group before its own group or the default. A person is in one group at a time; at most 500 per group. Apply this migration before deploying the 0.38 console, which reads the new column.
- **What wins:** a policy pushed with Intune, Group Policy or Google Admin wins over the console. The company connection (service address and key) is removed from console policies, both in the database and in the extension, so a mistake cannot cut a computer off.
- **Revoked key:** the function answers 401 and the computer drops the console policy.
- **Deploy:** run the migration with `npx supabase db push` and deploy the function with `npx supabase functions deploy device-policy` (it checks the company key itself, so `verify_jwt` is off in `supabase/config.toml`).

## Monthly compliance reports (Business Plus)

The **Monthly report** tab shows, for any of the last 13 months, what Step 1 can show as evidence for NIS2 Article 21(2) and ISO/IEC 27001:2022 Annex A: a protection score against the month before, coverage per protection, what was stopped, alerts, an evidence table with a status per measure, what to improve and every computer's state at month end. **Download PDF** opens the browser's print window, where people choose Save as PDF.

- **Board summary:** a one-page version for an owner or board, shown above the full report: the score and its change against the month before, what happened, the three most important things to do next, and how many measures have evidence. **Board summary (1 page)** prints only that page; the wording comes from `boardSummary()` in `service/web/compliance.js`.
- **History:** each report a computer sends adds a daily summary (its protection state and counts per day, never sites or content) to `device_days`. The daily job deletes days older than 13 months.
- **Who sees it:** companies on Business Plus, and companies in their trial, so the history is there when they upgrade. On Business the tab explains it is part of Business Plus.
- **Frameworks:** the **Framework** menu shows the same measures with references for NIS2 and ISO 27001, CIS Controls v8.1 IG1, Cyber Essentials or BIO2, and leaves out measures a framework does not have. BIO2 follows the ISO/IEC 27002:2022 numbering; its extra government measures are not covered. Browser updates (from the device checks) count as evidence for security update management.
- **Wording:** the report states evidence for specific measures and that it is not a certification. Multi-factor authentication comes from the Step 2 readiness check and is marked as stated, not measured. Have an auditor or insurer review the template before you sell it as evidence; the mapping is in `service/web/compliance.js`.

## Step 2 leads

The **Step 2** tab is a readiness check for the next step after Step 1: a full zero trust platform from a vendor such as Zscaler, Palo Alto Networks, Netskope, Cloudflare, Microsoft, Fortinet, Cisco, Check Point or Cato Networks.

- **What the company sees:** a readiness score out of 100 with what to do first, and up to three vendors that fit, with the reasons. The rules are in `service/web/readiness.js`. They use only the answers, never referral fees, and the page says so.
- **What is stored:** the answers and company totals from the overview (number of computers, personal devices, apps and AI tools in use, and so on). Nothing about individual people, sites or files.
- **Sharing:** nothing reaches you until someone in the company ticks the consent box and shares with their contact details. They see exactly what is shared, and **Stop sharing** removes their contact details.
- **Your inbox:** the daily job emails `ADVISOR_EMAIL` with each new or updated shared check: contact details, timing, budget, trigger, score, shortlist and all answers. A failed email is retried the next day.
- **Hot leads:** the goals question includes things Step 1 does not do itself: an isolated cloud browser, a file sandbox, company apps only from protected devices, and device health checks. Choosing one steers the shortlist to vendors that offer it, and the email subject says the company "asks for more than Step 1".

To see all shared checks at once, run this in the **SQL Editor**:

```sql
select c.name, r.contact_name, r.contact_email, r.contact_phone, r.shared_at,
       r.answers->>'timing' as timing, r.answers->>'budget' as budget, r.answers->'trigger' as trigger
from readiness_checks r join companies c on c.id = r.company_id
where r.shared_at is not null
order by r.shared_at desc;
```

Before you pass a lead to a vendor, check with the contact first, and join the vendor's partner programme so the referral counts. Use the contact details only for Step 2, and remove them if the company stops sharing or asks you to (it is part of `delete from companies …` as well).

## Not built yet

- Billing and invoices (planned: Paddle as merchant of record, setting `plan` and `paid_until` automatically).
- Inviting colleagues to a company; today each company has the person who created it.
- Deleting a company's data on request (GDPR); today this is a SQL `delete from companies where id = …`, which removes everything of that company.
- Website categories (Business Plus).
- Sending the monthly report by email; today people download it from the console.

## Before the first paying customer

- Use a paid Supabase plan with backups, and your own SMTP for sign-in emails.
- Have someone review the database rules and functions; the tests in `tests/service-db.test.js` and `tests/service-ingest.test.js` show what is intended.
- Write down who to contact and what to do if the service is breached or down.

## Tests

`npm test` runs the migration on an in-memory Postgres (PGlite) set up like Supabase, with the same roles and default grants, and runs the function logic against it. The Deno wrappers (`index.ts`) and Supabase itself are not run in tests.
