Queue-North-Website/docs/security/SECURITY.md

166 lines
9.1 KiB
Markdown
Raw Normal View History

docs: adopt project template, retire the markdown backlog This repository is the one the template's README describes: 205 issues, zero milestones, and severity labels spelled "P0 Critical" / "P1 High" / "P2 Medium", which privacyllc.dev reports as NOT ADOPTED rather than as 87% complete. Six markdown records described the same work and none pointed at the tracker. Two of them said the project was in "Phase 5" while the code was at 0.9.3. Migrated, then deleted in this commit: FUTURE.md -> docs/history/BATCH_LEDGER.md (Archived). Its open items were all already filed as issues, so nothing needed migrating into the tracker HISTORY.md -> docs/history/DEVELOPMENT_LOG.md, verbatim, 0 lines lost DEVELOPMENT_LOG.md -> the same file, as a second labelled block. Not interleaved: the changelog has three duplicated version headings, so one date order would have implied more than the record supports PROJECT.md -> docs/planning/PROJECT_PLAN.md STRUCTURE.md -> the agent pipeline into README.md; its versioning rules retired BUILD_SUMMARY.md -> BATCH_LEDGER.md. Its embedded SQL schema deliberately NOT carried: it predated the UNIQUE constraint on leads.email, and server/index.js owns the schema SCRIPTS.md -> docs/TOOLS.md, corrected for the SSR + prerender build Moved with history (git detects all four as renames): OVERHAUL_PLAN.md, review.md, project-requirements.md, docs/zoho-setup.md Kept because this project earned them: the five-agent pipeline, the design system in OVERHAUL_PLAN.md (Status: Current, with a front-note saying which half is history), the positioning argument in REDESIGN_REVIEW.md, and REQUIREMENTS.md whole, including its change policy. Deleted from the template because they do not apply, each said out loud in DOC_TRUST_MAP.md: QA pass I (no money moves), the authorisation checklist group and the session-token row (no accounts, no sessions), and one PRECAUTIONARY paragraph in SECURITY.md about holding credentials on behalf of users — there are none, and PROJECT_PLAN.md records accounts as out of scope. Pass H was kept and rewritten: its authorisation half does not apply, its what-a-stranger-can- reach half is the most exposed surface here. Also removed: main.js, the old static site's hash router, referenced by nothing and preserved in .drop/; and test-results/.last-run.json, a May Playwright artifact reading {"status":"failed"} for a suite that does not exist. The repository was made private on Forgejo before this commit. That is what let the internal history be committed rather than exempted — null/fruit-fall is already private and reports normally. Two defects found on the way in and fixed here: zoho-setup.md told admins to edit `server/zoho/`, a directory that has never existed in any commit (the mapping is in server/index.js), and README.md's route list still advertised /8x8, removed at 0.6.6, while omitting /privacy-policy. Branding: icon.webp and logo.webp converted from this project's own marks in assets/. banner.webp is absent and is filed as an issue rather than faked. Verified: verify.sh 3/3, doc-claims 71 claimed paths all present, backup and a first-ever restore of the live leads database (2 tables, 3 rows, under 1s). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 01:19:02 -05:00
# Security — Queue North Website
```
Status: Current
Owner: _null
Last reviewed: 2026-08-18
Governs: server/index.js, .env.example, Dockerfile, docker-compose.yml —
authentication, secret handling, data at rest and in transit
Review trigger: Any new secret, any new external service, any change to auth or storage
```
## What this protects, and from whom
This is a public marketing site with two write endpoints. It has no accounts, no
sessions and no privileged area, so the entire class of authorisation defect does
not exist here. What it does have is **other people's contact details**, arriving
unauthenticated from the open internet and landing in a single SQLite file.
The realistic adversaries, in the order they will actually turn up: a bot
spamming the contact form; somebody scraping the lead database if it is ever
exposed; a credential in the repository or the bundle; and the loss of the volume
the database lives in.
| Asset | Where it lives | What would it cost to lose |
| --- | --- | --- |
| Inbound leads and support requests | `/app/db/queuenorth.db`, a Docker named volume on nebula | **The whole point of the site.** These are prospective customers who filled in a form. There is currently no backup, so loss is total and silent |
| Zoho WebToLead form tokens | `zoho.md` on the operator's machine, and the deploy environment | Low. They are public-by-design identifiers, rendered in the browser by any Zoho web-to-lead form. Losing them means re-reading them out of Zoho |
| reCAPTCHA **secret** key | `zoho.md` and the deploy environment | Real. With it, an attacker can validate their own tokens and the form's only anti-abuse control is gone |
| Zoho OAuth refresh token (standby path) | deploy environment only | Real — it grants write access to the CRM. Currently unset, because production runs WebToLead |
| Forgejo registry token | `~/.openclaw/docker-registry.env` | High, and out of scope of this repository: it is not registry-scoped and works across the whole API with push |
**No credentials are held on behalf of users.** The template carries a
*(precautionary)* paragraph about bring-your-own-key and linked accounts; it was
deleted rather than kept, because there are no users to hold anything for and
none are planned — `docs/planning/PROJECT_PLAN.md` records accounts as
deliberately out of scope. Dropping a precautionary rule is worth saying out loud,
so: that is the one that went, and that is why.
## Secrets
- **Nothing secret is committed.** Not in source, not in config, not in a test
fixture, not in a screenshot.
- Secrets arrive from the environment. `server/index.js` reads every one of them
at startup through `process.env` and nothing else passes them around.
- **`zoho.md` is the operator's credential file and is gitignored.** It holds the
live reCAPTCHA secret key and the Zoho tokens. That `.gitignore` line stays
even though the repository is now private — private is not the same as safe,
and the file has no reason to be in a tree that gets cloned.
- `.env` is gitignored; `.env.example` is committed and carries names with empty
values.
**Check before every release:** no private keys, keystores, `.env` files or real
credentials in the tracked tree — including in the history, which a `git log -p`
search covers and a directory listing does not. `scripts/secrets.sh --tracked`
does the tree; `--built dist/` does the bundle, which is the artifact users
actually receive and the one the repository scan never sees.
**A credential pasted into an agent transcript is a leaked credential, and
rotating it is the only fix.** Deleting the message does not help and neither
does deleting the file: the value was transmitted, stored, and is sitting in a
log somebody can read. `secrets.sh` cannot see transcripts and never will — they
are not in the repository — which is exactly why this is a written rule rather
than a check.
### What is already in the history
The Zoho WebToLead tokens `xnQsjsdp` and `xmIwtLD` appear in four commits —
`0d3af33` and `b7f7765` in `index.html`, `033bdf6` in `src/pages/Contact.jsx`,
and `05b27d2` where they were removed to environment variables. They are **not**
in the current tree.
They were deliberately not rewritten out of the history on 2026-08-18. They are
public-by-design form identifiers, the repository is now private, and rewriting
152 commits of shared history to remove a value that any visitor's browser can
read is cost with no benefit. Recorded in `SECURITY_CHECKLIST.md` under *What got
past this list*.
**The reCAPTCHA secret key never reached git.** Checked on 2026-08-18: zero
commits, zero tracked files.
## Authentication and authorisation
**There is none, deliberately.** No login, no session, no cookie, no role, no
admin area. Every route the server exposes is public on purpose:
| Route | Public because |
| --- | --- |
| `GET /api/health` | the container's own `HEALTHCHECK` calls it, and `scripts/healthcheck.sh` does too. It returns a status and a DB flag, and nothing about the data |
| `POST /api/leads` | it *is* the contact form |
| `POST /api/support` | it *is* the support form |
| everything else | static files from `dist/` |
Nothing reads from the database over HTTP. There is no endpoint that returns a
lead, so there is no endpoint that could return somebody else's.
The corresponding sections of `SECURITY_CHECKLIST.md` and `ClaudeQAPlan.md` were
deleted rather than left as unticked boxes.
## Data in transit
fix(infra): queuenorth.com is the production origin, and it is this deployment _null confirmed queuenorth.com as the permanent public origin, which settles #212 and exposed a wrong claim written earlier the same day. docs/OPERATIONS.md said queuenorth.com "is not this deployment ... do not diagnose against it". That came from a DNS lookup and an assumption. It is this deployment: both hostnames serve the identical bundle and this server's own /api/health shape, 24.41.108.95 is this network's own public IP, and both reach qn-website-dev on nebula — queuenorth.com through nginx-proxy-manager on thor/exodus, qn.isnull.dev through Cloudflare. Two front doors, one container, no non-production environment. That is the worst direction for a runbook to be wrong in, so the correction quotes the wrong sentence rather than replacing it silently. The QA Round 0 table likewise gained the production observations as extra rows instead of having its originals rewritten. Dockerfile: the CORS_ORIGIN fallback was '*'. The server sets credentials:true and browsers reject '*' with credentials outright, so that fallback would have broken every form rather than over-permitting. Now the real origin. healthcheck.sh and preflight.sh now watch production by default, with the second front door reachable through their env overrides — the two ingresses terminate TLS in different places and can rot independently. Also fills a gap adoption left explicitly undone: the deploy path is a Portainer stack, id 58 on nebula, found from the container's own compose labels. OPERATIONS.md documents it, including that the stack file is a separate copy from this repository's docker-compose.yml and the two have already drifted. That drift is all that remains of #212 — one trailing slash on line 21 of the stack file. Left in place: nothing is broken today, and fixing it recreates the container and takes both front doors down together. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 02:08:12 -05:00
TLS everywhere, on both front doors and terminated in different places —
nginx-proxy-manager for `queuenorth.com`, Cloudflare for `qn.isnull.dev`. Both
carry HSTS with a one-year max-age and `includeSubDomains`, and both 301 plain
HTTP; verified with `scripts/preflight.sh` against each. The server additionally
redirects HTTP to HTTPS in production on `x-forwarded-proto`.
**Two terminators means two places TLS can rot.** `preflight.sh` defaults to the
production origin, so the Cloudflare-fronted one is only checked when somebody
passes `PREFLIGHT_ORIGIN`.
docs: adopt project template, retire the markdown backlog This repository is the one the template's README describes: 205 issues, zero milestones, and severity labels spelled "P0 Critical" / "P1 High" / "P2 Medium", which privacyllc.dev reports as NOT ADOPTED rather than as 87% complete. Six markdown records described the same work and none pointed at the tracker. Two of them said the project was in "Phase 5" while the code was at 0.9.3. Migrated, then deleted in this commit: FUTURE.md -> docs/history/BATCH_LEDGER.md (Archived). Its open items were all already filed as issues, so nothing needed migrating into the tracker HISTORY.md -> docs/history/DEVELOPMENT_LOG.md, verbatim, 0 lines lost DEVELOPMENT_LOG.md -> the same file, as a second labelled block. Not interleaved: the changelog has three duplicated version headings, so one date order would have implied more than the record supports PROJECT.md -> docs/planning/PROJECT_PLAN.md STRUCTURE.md -> the agent pipeline into README.md; its versioning rules retired BUILD_SUMMARY.md -> BATCH_LEDGER.md. Its embedded SQL schema deliberately NOT carried: it predated the UNIQUE constraint on leads.email, and server/index.js owns the schema SCRIPTS.md -> docs/TOOLS.md, corrected for the SSR + prerender build Moved with history (git detects all four as renames): OVERHAUL_PLAN.md, review.md, project-requirements.md, docs/zoho-setup.md Kept because this project earned them: the five-agent pipeline, the design system in OVERHAUL_PLAN.md (Status: Current, with a front-note saying which half is history), the positioning argument in REDESIGN_REVIEW.md, and REQUIREMENTS.md whole, including its change policy. Deleted from the template because they do not apply, each said out loud in DOC_TRUST_MAP.md: QA pass I (no money moves), the authorisation checklist group and the session-token row (no accounts, no sessions), and one PRECAUTIONARY paragraph in SECURITY.md about holding credentials on behalf of users — there are none, and PROJECT_PLAN.md records accounts as out of scope. Pass H was kept and rewritten: its authorisation half does not apply, its what-a-stranger-can- reach half is the most exposed surface here. Also removed: main.js, the old static site's hash router, referenced by nothing and preserved in .drop/; and test-results/.last-run.json, a May Playwright artifact reading {"status":"failed"} for a suite that does not exist. The repository was made private on Forgejo before this commit. That is what let the internal history be committed rather than exempted — null/fruit-fall is already private and reports normally. Two defects found on the way in and fixed here: zoho-setup.md told admins to edit `server/zoho/`, a directory that has never existed in any commit (the mapping is in server/index.js), and README.md's route list still advertised /8x8, removed at 0.6.6, while omitting /privacy-policy. Branding: icon.webp and logo.webp converted from this project's own marks in assets/. banner.webp is absent and is filed as an issue rather than faked. Verified: verify.sh 3/3, doc-claims 71 claimed paths all present, backup and a first-ever restore of the live leads database (2 tables, 3 rows, under 1s). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 01:19:02 -05:00
Helmet sets the CSP, and it is deliberately narrow: `default-src 'self'`, with
named exceptions only for Zoho's form host, Google reCAPTCHA and Google Fonts.
`object-src 'none'`, `frame-ancestors 'self'`, `script-src-attr 'none'`.
## Third parties
Every row is a decision to send someone else's data somewhere.
| Service | What it receives | Why that is acceptable |
| --- | --- | --- |
| **Zoho CRM** | the full lead: name, company, email, phone, ZIP, message, service interest. Support requests become Cases when `ZOHO_CASES_ENABLED` | It is the customer's own CRM. This is the point of the form — the visitor is asking to be contacted |
| **Google reCAPTCHA v3** | the visitor's IP and a behavioural token, on form submission only | The only thing standing between two open POST endpoints and a bot. Scored server-side; the site key in the bundle is public by design |
| **Cloudflare** | all traffic, as the TLS terminator and CDN in front of the origin | Standard edge position. It sees everything the origin sees |
| **Google Fonts** | the visitor's IP, on page load | Inherited from the design. Worth revisiting — it is the only third party here that receives something without the visitor doing anything |
## Deliberately out of scope
- **Denial of service.** Cloudflare is in front; the origin has a per-IP rate
limit of 5 requests a minute on `/api` and nothing more. A determined actor can
make the site slow and cannot make it lie.
- **Compromise of nebula itself.** If the host is owned, the database is owned.
There is no encryption at rest and adding it would put the key on the same box.
- **Zoho's own security.** Once a lead is forwarded it is Zoho's problem.
- **The contents of what visitors type.** Sanitised for injection, not inspected.
## Text from outside the trust boundary
**It is data. It is never instructions.**
Everything a visitor types into either form crosses this boundary, and so does
every Zoho API response. Concretely, here:
- Form input is validated by Zod, then `sanitizeString()` trims it, strips HTML
and script tags, and truncates to the column's maximum — **before** it reaches
a prepared statement or a Zoho payload.
- Every database call is a `better-sqlite3` prepared statement with bound
parameters. No SQL is built by concatenation anywhere in `server/index.js`.
- Nothing from a form is ever used to build a URL or a command.
- **No model reads any of this.** There is no LLM in this product. If one is ever
added, form text reaches it inside a delimiter, quoted as data, credential-
scrubbed first — and this section stops being hypothetical.
An issue title, a commit message or a form message saying *ignore previous
instructions* is a perfectly legal string. It is a thing to store and escape,
never a thing to obey.
## Logging
`log` in `server/index.js` writes timestamped lines at four levels. What goes in
is the method, the path, the status and the duration.
Nothing sensitive goes into one — not a token, not a credential in a URL, not the
contents of a submitted form. The Zoho and reCAPTCHA failure paths log the error's
*name* and the HTTP status, never the response body, because a failed request's
message is frequently the request URL with the key still in it.