Signing in

Every staff page asks for a password and then a second factor: a passkey or a code from an authenticator app. A session without the second factor is sent to the verify page.

  • Passkeys (WebAuthn) are verified by py_webauthn. User verification, a PIN or biometrics, is required on registration and on every sign-in. The relying party is the host of SITE_URL and the only accepted origin is SITE_URL’s own, never the request’s Host header. Each challenge lives in the server-side session and answers once. A signature counter that stands still or goes back is refused.
  • Authenticator codes (TOTP) keep their secrets encrypted with the vault key, so a copied database holds no usable seed.
  • Sign-in attempts are limited to ten per five minutes per address.
  • The last second factor of an account cannot be removed.
  • The Django admin is hidden behind a long random path, and production refuses to start with a short or placeholder one. Everyone but a superuser with a second factor gets a 404 there.

Step-up for sensitive changes

Changes that could move money or reroute a client need a superuser who gave a second factor within the last ten minutes.

  • Creating, rescoping or revoking an API token.
  • A rail account, its credentials and its BTCPay webhook.
  • A bank account or a payment link.
  • An organization’s US-resident issuer flag and the hosts it may send clients back to.
  • Adding a contact’s e-mail address or making one primary: letters, pay links and PDFs go there.
  • Removing another person’s second factor.

Anyone else gets a 403 and nothing changes. Every such change e-mails every active superuser with who, what and when, naming things by label and id: never a secret, an IBAN or a client’s address.

The sealed vault

Client data is encrypted with a key derived from a vault password the server never stores.

  • Derivation. PBKDF2-HMAC-SHA256 with 600,000 iterations and a random salt gives a Fernet key. The password must be at least 16 characters.
  • Where the key lives. In the process’s memory and in a file on tmpfs (RAM). Never in the environment, never on a persistent disk.
  • Sealed by default. A reboot or a wiped tmpfs seals the vault. A person unlocks it at /unlock/, five attempts per five minutes per address, or with manage.py unseal_vault, the password on stdin. A graceful reload keeps it open.
  • While sealed the client pages, payment links and the API answer 503. The chain watchers and payment matching read plaintext columns only and keep running; e-mail waits in the queue.
  • Tied to one installation. Every use of the key checks the vault.json it opened. If another installation’s file is put in its place, the process seals itself rather than write under the wrong key.

Encrypted database fields

56 model fields are stored as Fernet tokens.

  • Contacts: legal and display names, postal addresses, e-mail addresses, phone numbers, tax ids, notes.
  • Invoices: titles, notes, line-item names and descriptions, the frozen snapshot of what the client was shown, void reasons.
  • Organizations: bank account details (beneficiary, account number, SWIFT, intermediary bank), fiat payment link URLs, tax ids.
  • Secrets: rail credentials, webhook URLs and signing secrets, staff TOTP seeds, client encryption keys.
  • The outbox: recipients, subjects and bodies of queued e-mail.
  • Everything else personal: audit details, payment notes, payment-link checkout data.

What stays plaintext, on purpose: amounts, currencies, statuses, dates, invoice numbers, networks and transaction hashes. That is what lets payments be seen and matched while the vault is sealed. E-mail lookups go through a keyed blind index (HMAC-SHA256 under a key derived from the vault), not plaintext. A value the current key cannot open is never shown as if it were text.

Encrypted mail to clients

Each contact can have a PGP public key or an S/MIME certificate. Letters to that contact are then encrypted to it, as PGP/MIME or S/MIME.

  • Confirmed before use. An uploaded key waits until a link in a letter encrypted to it is answered, within seven days.
  • Replacing a key is announced. The key being replaced gets a notice with a cancel link, so someone who reads the client’s mailbox cannot swap in a key of their own unseen.
  • Refuse rather than downgrade. A contact with an active key never gets a plaintext letter. If the key stops working at send time, the letter fails instead of going out, and nothing is sent in plaintext until a person acts.
  • Throw-away keyrings. gpg works in a temporary keyring on a RAM disk, deleted after each use.

Client pages and links

  • Clients reach their invoice, their pay page and their key page only through capability links: 32 random bytes each, stored as SHA-256 hashes. An order from a payment link also keeps its two links encrypted under the vault key until its receipt is out, because the receipt carries them.
  • Those tokens are cut out of every logged path. The example Apache configuration logs no URL at all for these paths, and never a query string or a Referer.
  • Public pages are rate limited: page views, quotes, PDFs and declared transaction hashes.
  • Payment-link checkouts allow 5 attempts per 10 minutes per address and 50 completed checkouts per hour per link. Uploaded images are re-encoded with their metadata stripped.

Content Security Policy

Every response carries this policy, with a fresh nonce each time:

default-src 'none'; script-src 'self' 'nonce-…'; style-src 'self';
img-src 'self' data:; font-src 'self'; connect-src 'self';
form-action 'self'; base-uri 'none'; frame-ancestors 'none'

No inline event handlers, no style attributes, no framing. Only a verified superuser on the hidden admin path gets inline styles, which the Django admin needs.

No third parties in the browser

Fonts (Inter, JetBrains Mono) and htmx are served by your own installation.

The policy above lets a browser load nothing from anywhere else, so a client page cannot carry analytics, a CDN script or a tracking pixel. Tests fail if a page references a CDN.

Signed webhooks

  • Outgoing. Each event is canonical JSON, signed with HMAC-SHA256 over exactly those bytes and sent as X-Pay-Signature: sha256=<hex>. Only https, only to public addresses, checked when the endpoint is saved, before every delivery and again by the connection itself, so DNS rebinding cannot redirect it. Redirects are never followed. A failed delivery is retried for about sixteen hours, then waits for a person.
  • Incoming from BTCPay. The BTCPay-Sig HMAC is compared in constant time, and a missing or wrong one is refused. The body never decides anything: the invoice’s state is read back from BTCPay’s API. At most 120 requests a minute per address.

Scoped API tokens

  • Four scopes: read, invoices:write, payments:confirm and admin. A token belongs to one organization.
  • Stored only as a SHA-256 hash and compared in constant time.
  • 120 requests a minute per token.
  • A payment that waits for a person is confirmed or assigned only by a person: every token gets 409 needs_person. Recording a manual payment, “staff saw the money arrive”, is refused to every token too.
  • The MCP server for AI agents exits at start if its token holds payments:confirm or admin, and has no tool that confirms, refunds or voids anything.

Nothing that can spend

Sealbill receives money. It has no way to send any.

  • A chain rail is an address plus the networks and tokens to accept. No private key exists on the server.
  • Lightning and BTCPay credentials are stored only once they are shown to be receive-only: an NWC connection without any pay method, an LND macaroon limited to invoices and info, a Core Lightning rune limited to invoice and listinvoices, an LNbits invoice key, a BTCPay key limited to invoices.
  • Those credentials are encrypted with the vault key and never shown again. Each change is audited: which fields, never their values.
  • Rail URLs must resolve to public addresses, checked on save and on every call, so a credential is never sent to something listening on the server itself. Changing a rail’s host clears its credentials and deactivates it.

Exchange rates

  • Crypto prices come from two independent sources, Bitstamp and Coinbase. When they differ by more than 1% (100 basis points) the quote is refused.
  • Other fiat currencies go through the ECB rate, from Frankfurter. An answer more than five days old is refused, and so is one more than 10% away from the last rate accepted. A person accepts a jump that is real, and that is audited.
  • Arithmetic is Decimal throughout. Prices are parsed from strings, never from floats.

Confirmations and finality

A transfer is credited only once it is final.

ChainFinal when
Ethereum, Polygon PoS, BNB Smart Chain, AvalancheThe block is at or below the node’s finalized block
Arbitrum One, Optimism, BaseFinalized, or at least 5 minutes old and worth up to 1,000 USD
SolanaRead at finalized commitment
TronTronGrid reports it confirmed
Bitcoin through BTCPay1, 2 or 6 confirmations; a zero-confirmation policy is refused
Monero, Zcash through BTCPayBTCPay calls the invoice settled at your store’s threshold
  • A transfer’s identity is its transaction hash and its place in that transaction, so a reorg cannot record one transfer twice.
  • A BTCPay payment is read again for 72 hours after it is confirmed. If BTCPay then calls it invalid, a person decides; code never reverses anything.
  • Blocks a watcher could not read are recorded as gaps for a person, never guessed at.

Audit trail

Every change records who did what to which record, and when.

The details are encrypted. Actions the system takes on its own, which may run while the vault is sealed, record only plain facts: ids, amounts, states, networks, transaction hashes. No screen edits or deletes an entry; staff read the log under Settings.

Running it

  • Backups are one AES-256 archive (openssl, PBKDF2 with 200,000 iterations) holding the database dump and vault.json, written with mode 0600 and kept 14 days, with an HMAC-SHA256 beside it that the restore checks before it decrypts anything. The restore script refuses to replace a different vault.json without --force, and refuses while the app runs.
  • On a shared host gunicorn listens on a Unix socket only the web server’s group may open, and a proxy secret header proves each request came through the proxy. Production refuses to start without that secret unless you say no other account can reach the app. Rate limits key on the last X-Forwarded-For entry, the one the proxy appends.
  • The systemd units run with ProtectSystem=strict, ProtectHome, PrivateTmp and NoNewPrivileges.
  • /healthz reports the vault state, the worker’s heartbeat and counts of failures. No names, no client data.

Where it stops

What Sealbill does not protect against, and what it leaves to you.

  • While unsealed, the key is in the server’s memory. Whoever controls the running host, root included, can read it. The vault protects a stolen disk, a leaked backup or a copied database, not a compromised live server. In an incident, manage.py seal_vault removes the key from every running process.
  • Plaintext by design: amounts, statuses, dates, networks and transaction hashes, as listed above.
  • Your server talks to others. The chain watchers use public RPC endpoints unless you configure your own, and exchange rates come from Bitstamp, Coinbase and Frankfurter. Those services see your server’s address and what it asks for. A transfer on an EVM chain counts as final only once endpoints of two different operators agree on it, so one lying endpoint cannot invent a payment.
  • Native ETH sent by a contract (an internal transfer) is not seen. Staff record such a payment by hand.
  • Bank transfers and fiat links are recorded by a person. Nothing reads your bank.
  • Matching needs addresses only Sealbill uses. Money sent to the same address for any other reason lands in Needs a person.
  • TON is off until the credit to your own jetton wallet can be verified.