Skip to content

feat(member): self-service domain add+verify via WorkOS DNS challenge - #4440

Merged
bokelley merged 3 commits into
mainfrom
bokelley/public-visibility-domain-link
May 12, 2026
Merged

bokelley merged 3 commits into
mainfrom
bokelley/public-visibility-domain-link

Conversation

@bokelley

@bokelley bokelley commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds POST /api/me/organization/domains (issue WorkOS DNS-TXT challenge) and POST /:domain/verify so owners/admins can attach and verify a new domain without admin intervention.
  • Verified rows land at source='workos', which the existing PUT /:domain/primary already accepts — once primary, the Public visibility toggle on the agent dashboard unblocks automatically.
  • Linked Domains card on /member-profile gets an "Add a domain" form + per-row Verify button.

Why

Today, admins are paged whenever a member wants to publicly list an MCP agent on a domain not auto-promoted from WorkOS SSO. The dashboard's Public toggle is gated on organization_domains.is_primary=true with source='workos' — the member self-service set-primary endpoint hard-codes requireSource: ['workos']. Without a member-issued WorkOS challenge, the only path was admin override.

Active escalation: Santhosh @ Affinity Answers wants to make his MCP agent Public; affinityanswers.com is admin-attached so he can't promote it himself. With this change he runs the DNS challenge in the UI and unblocks himself.

Security model

The verify path keeps the documented upsertWorkosDomain ownership-transfer-on-conflict semantic — DNS proof is in hand, so a same-domain row on another org is correctly overridden. The issue path explicitly does NOT have DNS proof yet, so it:

  1. Pre-checks for a cross-org local row and returns 409 cleanly (avoids leaking a WorkOS resource).
  2. Uses linkDomain (refuses transfer on conflict) instead of upsertWorkosDomain for the local write.

Verify is rate-limited with the same 60s per-(org,domain) cooldown as brand-claim.ts to stop agentic loops from burning WorkOS quota on still_pending.

What changed

  • server/src/routes/me-organization-domains.ts — two new owner/admin-gated routes; in-process verify cooldown; cross-org pre-check; linkDomain at issue time.
  • server/public/member-profile.html — Add-domain form with TXT record callout (host + token + copy button) and Verify DNS button; pending rows in the list get a per-row Verify button. Section shows for owner/admin even when 0 domains. Add card hidden client-side for non-admin viewers.
  • server/public/dashboard-agents.html — "primary brand domain" hint deep-links to #linked-domains-section.
  • server/tests/integration/me-organization-domains.test.ts — 14 new tests including cross-tenant safety, message-regex collision fallback, broken-pending recreate, verify cooldown, and an end-to-end seam (issue → verify → set-primary by an owner with no admin in the loop).

Test plan

  • npx vitest run tests/integration/me-organization-domains.test.ts — 20/20
  • npx vitest run tests/integration/{organization-domains-db,brand-domain-resolver,me-organization-domains}.test.ts — 53/53
  • TypeScript clean (precommit gate)
  • code-reviewer, security-reviewer, adtech-product-expert reviews — all blockers / mediums addressed
  • CI green
  • manual e2e on staging (no existing Playwright coverage of Linked Domains)

🤖 Generated with Claude Code

bokelley and others added 2 commits May 11, 2026 22:15
Adds POST /api/me/organization/domains (issue WorkOS DNS-TXT challenge) and
POST /:domain/verify (confirm + flip verified=true) so owners/admins can
attach and verify a new domain without admin intervention. The existing
PUT /:domain/primary then accepts the row because source='workos' matches
the member self-service gate.

Closes the gap that forced admin handling for Santhosh @ Affinity Answers:
once verified by the member, the Public visibility toggle on the agent
card unblocks automatically (no admin role flip required).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
H1 (security blocker): At POST issue time there was no DNS proof yet, but
the route called upsertWorkosDomain which has documented ownership-transfer-
on-conflict semantics. A cross-org local-only row (source='manual' or
'import') for the same domain would be silently transferred to the caller's
org. Now: pre-check for a cross-org row and 409 cleanly; switch the issue-
time local write to linkDomain (refuses transfer); keep upsertWorkosDomain
only on the verify path where WorkOS confirms DNS proof.

M1: Added a 60s per-(org,domain) verify cooldown to stop agentic loops that
poll on still_pending from burning WorkOS quota. Mirrors brand-claim.ts.
Cleared on successful verify so follow-up "verify then set primary" isn't
penalized.

Product blockers: Linked Domains section now shows for owner/admin viewers
even when domains.length === 0 (orgs with no rows had no entry point at
all). Add-a-domain card is hidden client-side for non-admin members so
they don't see a button that 403s.

Nit: agent-card "primary brand domain" hint deep-links to
/member-profile#linked-domains-section, the actual flow.

Tests: cross-tenant safety (H1), message-regex collision fallback, broken-
pending delete-and-recreate, verify cooldown.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley

Copy link
Copy Markdown
Contributor Author

Expert reviews resolved

Security review (H1 ship-blocker):

  • Cross-tenant transfer at issue time: fixed in 85f9930. POST now (1) pre-checks for cross-org local conflict → 409 without touching WorkOS, and (2) uses linkDomain (refuses transfer) instead of upsertWorkosDomain. The transfer-on-conflict primitive stays only on the verify path, where DNS proof is in hand.
  • M1 verify cooldown: added — 60s per (org, domain), mirrors brand-claim.ts. Cleared on success.
  • M2 POST per-org rate limit: deferred per reviewer ("not critical pre-public-enable") — file a follow-up issue when widening exposure.

Code review:

  • Test gaps for message-regex collision fallback + broken-pending delete-and-recreate: added.
  • Optional helper for isVerified state check / XSS-invariant comment: not taken — the canonicalization regex closes the XSS surface at the source.

Product/UX review:

  • 0-domain entry point: Linked Domains section now shows for owner/admin viewers even with empty list.
  • Client-side role gate on Add card: matches domain-claim-section pattern at line 1721.
  • Deep-link the agent-card "primary brand domain" hint: now points to #linked-domains-section.
  • TXT-record host/type/value table + 409 collision → brand-claim flow: deferred — nice-to-haves, neither blocks Santhosh's case.

Ready for merge once CI clears.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 5c7ba29 into main May 12, 2026
13 checks passed
@bokelley
bokelley deleted the bokelley/public-visibility-domain-link branch May 12, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant