feat: custom domains by a unique CNAME, limited certificate orders #156

Merged
Sebi merged 3 commits from feat/custom-domain-abuse into main 2026-11-25 22:03:12 +00:00
Owner

Three commits:

1. Certificate orders for custom domains are limited

Status page servers order ACME certificates on demand. Only verified domains qualified, but nothing limited how many. One organization switching domains over and over, or many orders at once, could use up the CA's rate limits. For Let's Encrypt that is 300 new orders per account in 3 hours, and all platform servers share one account.

  • Certificate gate: before a new order (renewals are not asked), certmagic's cert_obtaining event calls POST /agent/v1/certificates. The API allows only verified domains of pages this server serves. Limits are counted in Redis across all instances:
    • UPTIME_CERTS_PER_NAME_PER_DAY (5)
    • UPTIME_CERTS_PER_ORG_PER_DAY (20)
    • UPTIME_CERTS_PER_HOUR (30): per ACME account owner, meaning the platform, or one organization's own servers.
  • Domain changes: at most 10 new custom domains per organization and day (domain_changes_exceeded).
  • Made-up names: the status page server remembers names without a page for 1 minute and passes at most 20 unknown names per second to the API. visited now records only real pages.

2. Custom domains are verified by a CNAME unique to the page

  • One record: status.example.com CNAME p<label>.<status page host>. The label is derived from the page's domain token. The wildcard record *.uptimesebi-status.net routes the domain. Because the target belongs to one page alone, the record also proves who set it up. A CNAME to the shared host would not prove that: any organization could then claim a domain pointing at the platform. The tests cover this case.
  • TXT stays for domains whose CNAME cannot be seen: behind a proxy such as Cloudflare, or without a subdomain (ALIAS, CNAME flattening).
  • Domain watch (every minute, one replica at a time through a Redis lock):
    • a new domain is checked every minute for 15 minutes, then every 10 minutes for 48 hours, and verified on its own;
    • verified domains are checked daily;
    • when the record is gone the owners get an email, and after 7 days the domain is switched off (second email), so a record left behind cannot be taken over;
    • domains verified before this change have no method and are not checked again.
  • Migration 00052: domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method.
  • Console: the CNAME record comes first, with "Check now". The TXT way for proxies and apex domains sits in a collapsible section. The editor says how the domain was verified and warns about a missing record with the date it will be switched off. The API returns cname_record and domain_missing_since. Texts in en and de.

3. Redis timeouts below a second

schedule.Take passed the rest of the long poll to BLPOP. When that was below a second, go-redis rounded it up to 1 s and logged specified duration is …ms, but minimal supported value is 1s. The poll then ran up to a second too long. Such waits now pass BLPOP a fraction of a second (Redis ≥ 6.0). The session's sliding expiry uses PEXPIRE.

Rollout

  • Update the API before the status page servers. A new server asking an old API orders no new certificates.
  • UPTIME_STATUSPAGE_URL must be set to the status page host, e.g. https://uptimesebi-status.net. Without it the console shows only the TXT way.

Tests

  • API: TestCertificateOrdersAreLimited, TestDomainChangesAreLimited, TestCustomDomainByCNAME, TestDomainsVerifiedBeforeAreNotCheckedAgain.
  • Status page server: negative cache, flood throttle, gate behaviour.
  • Scheduler: a short wait is no longer rounded up to a second, and a job pushed during it is received.
  • go test -p 1 ./..., go vet and gofmt are clean. The full suite no longer logs the Redis warning.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

Three commits: ## 1. Certificate orders for custom domains are limited Status page servers order ACME certificates on demand. Only verified domains qualified, but nothing limited how many. One organization switching domains over and over, or many orders at once, could use up the CA's rate limits. For Let's Encrypt that is 300 new orders per account in 3 hours, and all platform servers share one account. - **Certificate gate:** before a *new* order (renewals are not asked), certmagic's `cert_obtaining` event calls `POST /agent/v1/certificates`. The API allows only verified domains of pages this server serves. Limits are counted in Redis across all instances: - `UPTIME_CERTS_PER_NAME_PER_DAY` (5) - `UPTIME_CERTS_PER_ORG_PER_DAY` (20) - `UPTIME_CERTS_PER_HOUR` (30): per ACME account owner, meaning the platform, or one organization's own servers. - **Domain changes:** at most 10 new custom domains per organization and day (`domain_changes_exceeded`). - **Made-up names:** the status page server remembers names without a page for 1 minute and passes at most 20 unknown names per second to the API. `visited` now records only real pages. ## 2. Custom domains are verified by a CNAME unique to the page - **One record:** `status.example.com CNAME p<label>.<status page host>.` The label is derived from the page's domain token. The wildcard record `*.uptimesebi-status.net` routes the domain. Because the target belongs to one page alone, the record also proves who set it up. A CNAME to the shared host would not prove that: any organization could then claim a domain pointing at the platform. The tests cover this case. - **TXT stays** for domains whose CNAME cannot be seen: behind a proxy such as Cloudflare, or without a subdomain (ALIAS, CNAME flattening). - **Domain watch** (every minute, one replica at a time through a Redis lock): - a new domain is checked every minute for 15 minutes, then every 10 minutes for 48 hours, and verified on its own; - verified domains are checked daily; - when the record is gone the owners get an email, and after 7 days the domain is switched off (second email), so a record left behind cannot be taken over; - domains verified before this change have no method and are not checked again. - **Migration 00052:** `domain_set_at`, `domain_checked_at`, `domain_failing_since`, `domain_verify_method`. - **Console:** the CNAME record comes first, with "Check now". The TXT way for proxies and apex domains sits in a collapsible section. The editor says how the domain was verified and warns about a missing record with the date it will be switched off. The API returns `cname_record` and `domain_missing_since`. Texts in en and de. ## 3. Redis timeouts below a second `schedule.Take` passed the rest of the long poll to BLPOP. When that was below a second, go-redis rounded it up to 1 s and logged `specified duration is …ms, but minimal supported value is 1s`. The poll then ran up to a second too long. Such waits now pass BLPOP a fraction of a second (Redis ≥ 6.0). The session's sliding expiry uses PEXPIRE. ## Rollout - Update the API before the status page servers. A new server asking an old API orders no new certificates. - `UPTIME_STATUSPAGE_URL` must be set to the status page host, e.g. `https://uptimesebi-status.net`. Without it the console shows only the TXT way. ## Tests - API: `TestCertificateOrdersAreLimited`, `TestDomainChangesAreLimited`, `TestCustomDomainByCNAME`, `TestDomainsVerifiedBeforeAreNotCheckedAgain`. - Status page server: negative cache, flood throttle, gate behaviour. - Scheduler: a short wait is no longer rounded up to a second, and a job pushed during it is received. - `go test -p 1 ./...`, `go vet` and `gofmt` are clean. The full suite no longer logs the Redis warning. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 1 commit 2026-11-25 21:39:15 +00:00
feat: guard certificate orders for custom domains and explain the setup
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 8m21s
ci / lint (pull_request) Successful in 11m0s
ci / build (pull_request) Canceled after 8m49s
ci / image (pull_request) Canceled after 0s
db36d918fe
Status page servers order certificates on demand. Verified domains were
already the only ones they would order for, but nothing bounded how many:
an organization switching domains, or many organizations at once, could use
up the CA's rate limits that all servers sharing an ACME account depend on,
and every handshake or request for a made-up name was passed on to the API.

- Before a new order (not a renewal) the server asks the API
  (POST /agent/v1/certificates). It allows verified domains of pages that
  server serves, within limits per domain and day, per organization and
  day, and per ACME account owner and hour (UPTIME_CERTS_*), counted
  across all instances.
- An organization can set a new custom domain at most 10 times a day.
- The server remembers names without a page for a minute and passes at
  most 20 unknown names a second on to the API; pages the sync cached are
  not affected. Only real pages are recorded as visited.
- The page editor explains the three steps: the TXT record, the CNAME
  record with the platform's status page host as its target (or the
  organization's own servers), apex domains, and when HTTPS follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 2 commits 2026-11-25 21:59:09 +00:00
A checker's long poll ends with BLPOP waiting the rest of it, often below
a second, which go-redis rounded up to one second with a warning in the
log; the poll then ran up to a second too long. Such waits now pass BLPOP
a fraction of a second, which Redis takes since 6.0. A session's sliding
expiry, which can be below a second near its absolute end, uses PEXPIRE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
feat: verify custom domains by a CNAME unique to the page
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / lint (pull_request) Successful in 7m28s
ci / test (pull_request) Successful in 12m52s
ci / build (pull_request) In progress
5934bd74e8
A custom domain now needs a single record: a CNAME to
<label>.<status page host>, where the label is derived from the page's
domain token. The wildcard record of the status page host routes it, and
since the target belongs to one page alone it also proves who set it up;
a CNAME to the shared host would not, as any organization could then
claim a domain pointing at the platform. The TXT record stays for domains
whose CNAME cannot be seen, behind a proxy or without a subdomain.

- The domain watch looks for the records of a new domain every minute for
  a quarter of an hour, then every ten minutes for two days, and verifies
  it on its own; "Check now" still works.
- Verified domains are checked daily. When the record is gone the owners
  are told, and a week later the domain is switched off, so a record left
  behind cannot be taken over. Domains verified before keep working
  without checks.
- The editor shows the CNAME record first, the TXT way for proxies and
  apex domains, how the domain was verified and when a missing record will
  switch it off. The API returns cname_record and domain_missing_since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi changed title from feat: guard certificate orders for custom domains and explain the setup to feat: custom domains by a unique CNAME, limited certificate orders 2026-11-25 21:59:24 +00:00
Sebi merged commit ebfada4b2c into main 2026-11-25 22:03:12 +00:00
Sebi deleted branch feat/custom-domain-abuse 2026-11-25 22:03:15 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ZB-Server/uptimesebi#156