# POLLA security

 No real names or personal emails are published.

## Reporting a vulnerability

**Please do not open a public issue.** Report privately, through either channel:

- GitHub: *Security → Report a vulnerability* on this repository (private advisory).
- Email: **info@polla21.org**.

Include what you found, how to reproduce it and what an attacker could gain. We aim to answer within 72 hours and to fix anything that puts sats or participants' privacy at risk before a public disclosure, which we will coordinate with you. Please do not test against real draws with real sats: use test mode (`POLLA_TEST_MODE=1 node server/test-mode.mjs`, see [docs/TEST-MODE.md](docs/TEST-MODE.md)).

**In scope:** anything that could move sats, change or predict a result, double-pay or block a claim, link a purchase to a person, or let someone act as the admin. **Out of scope:** volumetric DoS against polla21.org, social engineering, and reports from automated scanners without a concrete impact.

## Security model in one paragraph

Nothing that decides a draw depends on a secret in this repository. The code is public on purpose (it is also served by the website itself); the only secrets live on the server, outside the repository: the lottery's Nostr key (`/etc/polla/nsec`) and a receive-only wallet connection (`/etc/polla/nwc`), both mode 600. Prizes are paid by hand with a one-time connection that never reaches the server. Admin actions require a NIP-98 signature from an allowlisted key. The sections below record past incidents and the reasoning behind each control.

## C1 — NWC strings in the history

On 12–13 Nov 2026, during early development and before the website had a server, two `nostr+walletconnect://` URIs were published in a `config.json`. Such a string can spend from the wallet it belongs to, so both connections are treated as compromised and must stay revoked.

What the operator has to do by hand:

1. In the wallet, revoke or rotate **every** NWC connection used in this draw (the original and any replacement).
2. Never paste an NWC string in the public `config.json` or in the panel again.
3. `public.nwc` must stay empty in `main`.

The panel and `buildConfigJson()` refuse to publish a `config.json` if `public` contains an NWC URI, a GitHub token (`ghp_`, `github_pat_`, …), a Nostr private key (`nsec1…`) or a wallet admin key or macaroon in recognisable fields (`adminkey`, `macaroon`, …). The contacts public key (`contactKey`) may go in `public`: it is public on purpose.

## M3 — GitHub token

The token (PAT) with Contents permission **is not stored in the vault or in the published `config.json`**. It only stays in that browser's `sessionStorage`, until the tab is closed.

If an old vault still carries the encrypted token, the panel opens it normally, moves the token to `sessionStorage` and, when saving or publishing again, removes it from the vault. Any token that has been in a public `config.json`, even encrypted, should be rotated in GitHub.

## M4 — Payment privacy

The website only talks to our own server (`server/`). It carries no wallet token: nothing in the public `config.json` can create invoices on someone else's account or list a payment history.

- **Collecting — NWC IN:** a Nostr Wallet Connect connection that can only receive (`make_invoice`, `lookup_invoice`, `get_info`), stored in `/etc/polla/nwc` (600, user `polla`). It is never written to the log or the repo.
- **Paying — NWC OUT:** a one-time connection the owner creates in their own wallet for each payment, pastes in the panel and deletes right after. It is never stored and never reaches the server.
- The lottery nsec lives in `/etc/polla/nsec` (600). The server refuses to sign with a key that is not the official one or with the two burned keys.
- The public invoice views never carry the payment hash or the invoice; the purchase id is random.
- Contacts are encrypted (ECDH + AES-GCM) with the admin key; they are never written in clear in the invoice.
- The secret claim code is neither published nor sent: only its hash (see [docs/claim-log.md](docs/claim-log.md)). Claims go signed over HTTPS to the server, which marks the prize on disk before anything is paid (no double collection even if two claims arrive at once or after a restart).

## My tickets and owner verification (phase 1 limits)

- Purchases stored in the browser are encrypted (AES-GCM, non-exportable key in IndexedDB, optional passphrase). What earlier versions left in clear is migrated and deleted after checking it.
- The contact verifier (`v1.<salt>.<hash>`, PBKDF2 with a per-purchase salt) stays **only in the buyer's browser**. Since 23/11/2026 it is neither sent to the server nor published: before, the public invoice list returned it with the encrypted contact, and anyone with a list of public npubs/emails could test them offline and link purchases (and prizes) to people.
- The public invoice views carry the description without the encrypted contact or the verifier (`publicDesc`). The panel gets the encrypted contacts with the admin signature (`GET /api/admin/contacts/:id`).
- A purchase made in another browser is opened with its secret code (checked in the browser) or through Nostr. The attempt limit of the local checks is **per browser**.
- The back of the ticket is not enough to collect (unless it is a bearer ticket): collecting requires the secret code. Details: [docs/my-tickets.md](docs/my-tickets.md).

## Dependencies

- The QR code generator (Kazuhiko Arase's «QRCode for JavaScript», MIT) is **vendored** in `vendor/qrcode-arase.js`. Each page loads it with `integrity` (SHA-384), checked against the file by `tests/security.test.mjs`. No script, font or style is loaded from a third-party CDN.
- **Content-Security-Policy** (Caddy, same text as `CSP` in `server/lib/http.mjs`, tested): code, styles and fonts only from our own origin (inline allowed for the theme script in `<head>`), no `<object>`, no framing (`frame-ancestors 'none'`), `base-uri 'none'`. Plus `X-Content-Type-Options: nosniff` and `Referrer-Policy: no-referrer`.
- `nostr-tools@2.10.4` is **vendored** in `vendor/nostr-tools-2.10.4.js`. The file's SHA-384 is pinned in `common.js` (`NOSTR_TOOLS_SHA384`) and checked by `tests/security.test.mjs`. It is not imported from a CDN.
