A signing link goes to someone who has no account in your app. Countersign has to show, later and to a third party, that a particular person signed a particular content. This page says what each secret proves, where it is kept, and what an attacker who holds one part still cannot do.

To report a vulnerability, see SECURITY.md in the repository.

  • 32 random bytes, URL-safe base64 (43 characters), in the link's path.
  • Stored only as its SHA-256 (signing_requests.token_hash), plus an AES-256-GCM ciphertext so the one reminder can carry the same link.
  • A resend issues a new token; the old link stops working, and a signing page still open on it signs nothing ({:error, :unusable}).
  • Signing, declining, revoking, expiring and failing clear the reminder's ciphertext, so no further message can carry the link. The hash stays: a dead link still opens the landing page, which names the sender and offers nothing more, and a signed request's link leads, after a fresh code, to the signer's copy for 30 days.
  • Every token is looked up by its hash whatever its shape, then checked (Countersign.Token.valid_format?/1), so a malformed token costs the same as an unknown one and its timing reveals nothing.

The token alone signs nothing. A forwarded email, a link in a browser history or a proxy log opens the landing page, which only offers to send a code to the address the link went to.

Keep it out of logs and referrers: mount the pages with referrer-policy: no-referrer, keep the /sign paths out of your request log, and never log a Countersign.Request field by hand.

The signing code

  • Six digits, sent to the request's own address and channel, never to an address the visitor types.
  • Stored as a Bcrypt hash; it lives 10 minutes and allows 5 guesses.
  • Each guess is spent by a conditional UPDATE before Bcrypt runs, so parallel guesses cannot exceed the limit; a wrong request id still runs a dummy Bcrypt, so timing does not reveal which part was wrong.
  • At most 3 codes per request per 10 minutes and 10 per day, plus the scope's own daily ceiling (Countersign.Host.codes_per_day/1), all through your Countersign.Host.check_rate/3. Your counter must be shared across nodes, or each node grants the limits again.

A correct code proves control of the address: the attribution the US ESIGN Act and UETA ask for.

The session

A verified code puts %{"request_id" => id, "verified_at" => unix_seconds} in the signer's Phoenix session under the config's :session_key. The review, sign and copy pages admit a visitor only when:

Anything else goes back to the landing page, which never says which check failed. The verification belongs to the browser that entered the code: a second browser with the same link has to ask for its own code.

Your session cookie must be signed (Phoenix's default) and served over HTTPS. With :client_ip_session_key, the pages record the client IP your own plug put in the session, so a page behind a proxy records the signer, not the proxy.

  • Consent records the disclosure's version and its SHA-256, so the exact wording the signer accepted can be shown later.
  • Signing runs in one transaction: your subject lock, then the request row FOR UPDATE, re-checked as live, verified within 30 minutes, consented, and opened on the current token; the subject is fetched again and its content hash compared with the hash the request was sent against; then your Countersign.Signable.record_signature/4. A moved hash, a subject gone or no longer signable, or your :changed or :already_signed answer records no signature and commits the request as superseded; any other refusal rolls all of it back and the request stays pending.
  • So a signature binds a person (the address they proved), an intent (an explicit act on the signing page), a consent (the disclosure they accepted) and a content (the hash), with the IP and user agent of the request that signed.

Data at rest

  • Addresses are encrypted with AES-256-GCM under a key derived from your secret_key_base; each purpose (address, token, code) has its own derived key, so one ciphertext can never be decrypted as another.
  • An address digest (HMAC-SHA256 of the normalised address, its own key) lets you find requests by address without storing it in clear.
  • Schema fields that hold secrets are redact: true.
  • Rotating secret_key_base makes the stored addresses and tokens unreadable: open links stop working and must be resent.

The certificate and the seal

The signing certificate records the request's whole history (sent, viewed, code verified, consented, signed) with times, IPs and the content hash. Countersign.Seal.seal/3 can seal it, and any PDF you store, with an Ed25519 and an SLH-DSA PAdES signature, so the file proves by itself that it was not altered. Verify with Countersign.Seal.verify/2 and your own certificates as :trusted: anyone can make a self-signed certificate under your name. Keep the seal keys in your secret store; the seal reads no configuration and no environment.

What Countersign does not do

  • It does not decide whether an electronic signature is valid for a given document in a given jurisdiction. That is a question for your counsel.
  • It does not authenticate the signer beyond control of an address. For a document that needs more (an ID check, a notary), add that step in your app before you send.
  • It does not store the document. Your app keeps it, and your content hash is what ties a signature to it.