Skip to content

fix(brand-registry): cross-org dispute escalations + clear manifest on relinquish - #3168

Merged
bokelley merged 4 commits into
mainfrom
bokelley/brand-delete-leak-and-disputes
Apr 25, 2026
Merged

bokelley merged 4 commits into
mainfrom
bokelley/brand-delete-leak-and-disputes

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Two follow-ons to the transfer-tool work in #3159, closing the second part of #3152.

Cross-org disputes route through escalations

When `updateBrandIdentity` rejects a write because the domain is owned by a different org, both the web `PUT /api/me/member-profile/brand-identity` route and the `update_company_logo` member tool now file a `category: needs_human_action` escalation instead of returning a bare 403.

The escalation captures:

  • Caller org, owner org, brand domain in `addie_context`
  • Original logo/color values in `original_request` so an admin doesn't have to ask
  • A summary that names both orgs

Web returns `409` + `escalation_id`. Chat returns a "we filed it (ticket #N)" message. Admins resolve via the existing `transfer_brand_ownership` tool.

Relinquish clears brand_manifest

`deleteHostedBrand` previously cleared ownership fields (`workos_organization_id`, `created_by_user_id`, etc.) but left the prior org's `brand_manifest` on the row. Triage flagged this as a spoofing path: a later soft-claim silently inherited the prior org's logos, colors, agents, and narrative copy.

The row now resets to a clean discovered state on relinquish — manifest cleared, `is_public` false, `brand_name` null. The domain key is preserved so external references survive, but a new claimant starts blank.

BrandIdentityError discriminator

The error class gained `code` (`invalid_input` | `invalid_domain` | `no_brand_domain` | `cross_org_ownership`) and a `meta` payload so route + tool callers can tell ownership conflicts apart from validation failures without parsing the error message. Existing throws were annotated; default code is `invalid_input` so the change is backward-compatible.

Out of scope (still parked from #3152)

The "soft-claim with verified-domain takeover" piece — letting a verified-domain owner take over a soft-owned row — is deferred. Pointer-only domain verification (the current mechanism, no challenge/response) isn't strong enough to gate a provenance change. The Explore agent confirmed `generateVerificationToken` is dead code that was stubbed for a DNS-TXT or file-placement flow that never shipped. Wiring that is a bigger piece of work.

Test plan

  • Type-check clean
  • 832 unit tests pass
  • New 4-case test for `BrandIdentityError` discriminator (`server/tests/unit/brand-identity-error.test.ts`)
  • Reviewer to verify staging: simulate a cross-org write attempt, confirm a 409 with escalation_id + the matching escalation appears in the admin queue.

🤖 Generated with Claude Code

bokelley and others added 2 commits April 25, 2026 11:29
…ifest on relinquish

Two follow-ons to the transfer-tool work in #3159:

- Brand-ownership disputes route through escalations now. The bare 403
  from updateBrandIdentity becomes a category=needs_human_action ticket
  with the caller org, owner org, and brand domain in addie_context.
  Web route returns 409+escalation_id; chat tool replies "we filed it"
  with the ticket number. Admins resolve via the existing
  transfer_brand_ownership tool.

- Relinquishing a hosted brand now clears brand_manifest. Before, only
  ownership fields were cleared, so a later soft-claim silently
  inherited the prior org's logos, colors, agents, and narrative copy.
  The row resets to a clean discovered state.

BrandIdentityError gained a `code` discriminator and `meta` payload so
callers can tell cross_org_ownership apart from validation errors.

Closes the second part of #3152. Soft-claim with verified-domain
takeover is still parked — pointer-only domain verification isn't
strong enough to gate provenance changes without a real
challenge/response.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Three small items from code-reviewer on #3168, all addressed:

* Chat false-promise on escalation failure. The previous code told the
  user "they'll resolve it and follow up" even when createEscalation
  rejected — a confidently false promise. Now branches on the null
  return: ticket-id message on success, "please email support" on
  silent failure. Web side now also flips its message text based on
  whether the escalation actually filed.
* Tightened BrandIdentityError meta typing. Switched from
  Record<string, unknown> to a per-code interface (BrandIdentityErrorMetaByCode).
  Added an isCrossOrgOwnership() type guard so catch sites narrow both
  the discriminator and the meta payload — err.meta.brandDomain is now
  typed as string instead of unknown. Catches typos at compile time.
* Caller email + display name added to addie_context so admins reading
  the escalation know who's asking without joining against a user table.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley and others added 2 commits April 25, 2026 11:56
…ions

Replaces the hard-reset behavior in #3168's first commit with the
flag-for-adoption design adtech-product-expert recommended in review.

* Migration 430 adds manifest_orphaned + prior_owner_org_id columns to
  brands.
* deleteHostedBrand now sets manifest_orphaned=true and stashes the
  prior owner instead of clearing the brand_manifest. Paired with
  is_public=false so public reads still don't surface the orphaned
  identity, and resolveBrand in member-profiles.ts skips orphaned rows.
* updateBrandIdentity gains an adoptPriorManifest flag. When the
  claimed brand is orphaned: default = clear and start fresh (safe
  against silent inheritance); opt-in = keep prior manifest and merge
  new claimant's logo/color over it (acquisition/handoff case). Either
  branch clears the orphan flag and reasserts is_public=true. Plumbed
  through to the PUT /brand-identity body as adopt_prior_manifest and
  surfaced in the response as adopted_prior_manifest.

Escalation framing changes per adtech-product-expert review:
* category switched from needs_human_action to sensitive_topic — these
  are governance/legal decisions, not routine triage.
* Summary and addie_context rephrased to not presume bad faith. The
  dispute could equally be an acquisition, naming overlap, or someone
  backfilling on behalf of the registered org.

Self-service "publish brand.json to auto-resolve" hint deferred until
that path actually exists — filed as #3176.

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

Security review surfaced two H findings: the verify-by-pointer route
bypassed the orphan logic (claimed-but-orphan = new owner with prior
manifest), and two unauthenticated registry-resolve routes leaked the
orphaned manifest before any claim. Code review surfaced a misleading
result field. Adtech-product review pushed for explicit-decision-required
on claim time.

Changes:

* claimOrphanedHostedBrand new DB method that atomically asserts
  ownership, marks verified, clears the orphan flag, and (default)
  resets the prior manifest. Verify-by-pointer route now uses this when
  hosted.manifest_orphaned is true. Without this, an org publishing a
  brand.json pointer at a relinquished domain became the verified owner
  with the prior org's logos still attached.

* Public read paths now filter orphaned + non-public:
  - /api/brands/resolve and /api/brands/resolve/bulk
  - /api/me/community-profile/:slug brand resolution in http.ts
  - /api/referral/:code referrer logo lookup

* HOSTED_BRAND_COLUMNS includes manifest_orphaned + prior_owner_org_id
  so every getHostedBrandByDomain caller can branch on orphan state.
  HostedBrand interface gained the matching optional fields.

* brand-feeds getBrandForEdit rejects orphaned brands so feed/property
  edits can't write into the prior owner's manifest fields during the
  pre-claim window.

* updateBrandIdentity now requires the orphan-adoption decision to be
  explicit. When manifest_orphaned and adoptPriorManifest is undefined,
  throws BrandIdentityError(409, 'orphan_manifest_decision_required')
  with the prior owner's org id in meta. Web route returns 409 with
  prior_owner_org_id in the body; chat tool replies with the choice
  question and prompts the user to re-run with adopt_prior_manifest
  set explicitly.

* Result fields renamed: adoptedOrphanedManifest (which fired even on
  clear) split into claimedOrphanedBrand + keptPriorManifest. Web
  response now exposes claimed_orphaned_brand + kept_prior_manifest.

* Cross-org dispute escalation summary now names the incumbent org
  too — "Brand ownership review: {domain} — claim by {claimant} vs
  current owner {incumbent}" — so admins triaging the queue see both
  parties at a glance.

* update_company_logo tool gains an adopt_prior_manifest input so
  members can opt in via chat after the orphan-decision question.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit dc2c14e into main Apr 25, 2026
14 checks passed
@bokelley
bokelley deleted the bokelley/brand-delete-leak-and-disputes branch April 25, 2026 16:20
bokelley added a commit that referenced this pull request Apr 25, 2026
…ol (#3182)

* feat(admin): list_orphaned_brands tool to audit relinquished brand pool

When a hosted brand is relinquished, the row sits in an orphaned state
(manifest preserved for adoption, paired with is_public=false). #3168
shipped the relinquish + adoption plumbing but left admins without a
view into the queue. Adtech-product-expert flagged this as a 6-month
data-hygiene problem if the admin tool didn't follow.

* New BrandDatabase.listOrphanedBrands joins organizations to surface
  the prior owner's display name alongside its id, plus a manifest
  preview (logo URL, brand color) so the queue is readable without
  drilling in. Newest-first ordering.
* New list_orphaned_brands admin MCP tool wires through to the admin
  tool set so the router can surface it.
* Returns days_since_relinquished computed at read time so admins can
  spot stale entries without timestamp math.

Pairs with transfer_brand_ownership for the resolve path. Listed brands
become claimable through the normal brand-identity flow (which already
forces explicit adopt-or-clear).

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

* Address review feedback on list_orphaned_brands

* relinquished_at field renamed to last_updated_at in the DB result
  shape — code-reviewer flagged the naming as a foot-gun since the
  value is sourced from the row's updated_at column. Added a comment
  documenting the relationship: while orphaned, only deleteHostedBrand
  writes to the row, so updated_at == relinquished_at in practice; if
  a future code path breaks that invariant, swap to a dedicated
  manifest_orphaned_at column.
* days_since_relinquished retained at the handler boundary (still the
  right thing to surface to admins reading the queue).
* Audit logger.info added on every invocation with adminUserId, count,
  limit, offset — security-reviewer's defense-in-depth note. Bulk
  enumeration of the orphan pool is now visible in logs.

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request Apr 25, 2026
…ty form (#3185)

* feat(member-profile): orphan-adoption decision prompt in brand-identity form

#3168 made adopt-vs-clear an explicit decision in the API (409 with
code orphan_manifest_decision_required), but the dashboard form only
surfaced that as a generic error message. A member trying to claim a
previously-registered domain had no way to pick.

This commit adds the inline prompt:

* Hidden #orphan-decision-prompt panel above the brand-edit form,
  shown when the server returns 409 + the orphan code.
* saveBrandIdentity captures the pending save context, pops the
  prompt with the prior owner id, and re-fires when adopt or fresh
  is clicked. Cancel dismisses without writing.
* Success message now reads "adopted prior identity" or "started
  fresh" so members can confirm which path landed.

Backend was already wired (#3168). This is the UX surface that makes
the design usable.

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

* Address review feedback: drop org id from prompt, switch to inline onclick

Security-reviewer (Low/defense-in-depth): user-facing prompt no longer
echoes prior_owner_org_id back. The 409 response still includes it for
support diagnostics and tooling, but a member who has never seen that
id has no way to act on it, and a screenshotted prompt won't leak the
prior owner's id externally.

Code-reviewer (style): switched orphan prompt buttons from
DOMContentLoaded-wired listeners to inline onclick, matching the rest
of the file's house style. Dropped the now-unused id attributes and
DOMContentLoaded handler.

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request Apr 25, 2026
* test(integration): cover the brand orphan-adoption transaction end to end

Code-reviewer flagged the test gap on #3168 — the orphan-adoption flow
had only the unit-level error-class test, no DB-shaped coverage. This
adds the integration suite using the existing `tests/integration/`
pattern (real Postgres at DATABASE_URL, .example.com fixtures, beforeEach
cleanup).

Coverage:
* deleteHostedBrand — orphan flag set, prior_owner_org_id stashed,
  manifest preserved, is_public=false, ownership cleared
* getDiscoveredBrandByDomain — row still returned with orphan flag
  exposed so callers can filter
* updateBrandIdentity — implicit decision throws 409
  orphan_manifest_decision_required with prior-owner meta
* updateBrandIdentity — adoptPriorManifest=false starts fresh
* updateBrandIdentity — adoptPriorManifest=true merges new logo over
  the prior manifest (prior colors persist)
* Cross-org write still fires cross_org_ownership even with adopt set,
  confirming the orphan path doesn't bypass the boundary

checkLogoUrlIsImage is mocked at the module-graph level so the test
doesn't make outbound HEAD requests against the .example.com URLs.

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

* Address review feedback on integration tests

* Cross-org test asserts the specific code='cross_org_ownership' (not
  just "any BrandIdentityError"). Without this, a regression that
  flips that branch to orphan_manifest_decision_required — silently
  letting cross-org writes through — would still pass. Code-reviewer
  flagged this as a real correctness gap.
* Collapse the duplicate updateBrandIdentity call in the
  orphan_manifest_decision_required test into a single
  rejects.toMatchObject that pins both code and meta.
* Strengthen the adoptPriorManifest=true assertion: also confirm prior
  brand id and names survive the merge, so we're not accidentally
  asserting on one untouched-by-coincidence field.
* Scope cleanup to this file's specific TEST_DOMAIN + test org ids
  rather than sweeping the entire .example.com pattern. Removes the
  parallelism foot-gun nodejs-testing-expert flagged: brand-registry-
  list.test.ts and this file would otherwise step on each other if
  vitest ran them in parallel.

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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