Skip to content

fix(security): validate brands.house_domain on write-path (#3467) - #4613

Merged
bokelley merged 1 commit into
mainfrom
fix/3467-validate-house-domain-write-path
May 17, 2026
Merged

bokelley merged 1 commit into
mainfrom
fix/3467-validate-house-domain-write-path

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Closes #3467 (bounded executable items only; see follow-ups below for the architectural questions).

Threat model

The brand-hierarchy auto-link path in server/src/db/org-filters.ts walks brands.house_domain and gates membership inheritance on brand_manifest->'classification'->>'confidence' = 'high'. Every community write surface (save_brand MCP tool, editDiscoveredBrand, upsertDiscoveredBrand) accepted both fields as opaque JSON.

Pre-fix attack:

POST /mcp save_brand
{
  domain: "attacker.example",
  house_domain: "paying-target.example",
  brand_manifest: { classification: { confidence: "high" } }
}

Then sign in from @attacker.example. The recursive org-chain join in org-filters.ts matches house_domain = paying-target.example AND the JSONB confidence gate, and (if the paying target opted into auto_provision_brand_hierarchy_children) autoLinkByVerifiedDomain issues the attacker a WorkOS membership in the paying target.

The strongest current guard is that auto_provision_brand_hierarchy_children defaults to false. This PR narrows the attack surface for orgs that have opted in.

Bounded items shipped

All three at the DB layer in server/src/db/brand-db.ts so every caller (MCP, HTTP, Addie tools, admin routes, crawler) inherits the same enforcement:

  1. Sanitize community-submitted brand_manifest — classification.* is stripped from any caller-supplied manifest. Trusted classification flows exclusively through a new typed UpsertDiscoveredBrandInput.classification field that only the brand-classifier service (brand-enrichment.ts) populates.
  2. Validate house_domain on every write — canonicalized via canonicalizeBrandDomain, validated via assertValidBrandDomain, rejects control characters (NUL/CR/LF) and self-references. Applied to upsertDiscoveredBrand, createDiscoveredBrand, editDiscoveredBrand.
  3. Preserve prior trusted classification on edit — a refresh-logos edit no longer drops the classifier's verdict by accident (and a caller can't downgrade confidence='high' to 'low' via an edit).

Regression test in server/tests/unit/brand-db-house-domain-validation.test.ts exercises the hostile payload against all three write methods (10 tests, all green).

Architectural questions — need decision before scope (Y) is touchable

These are intentionally NOT in this PR. Calling them out for human decision:

  • DNS/WorkOS ownership proof on admin PATCH (server/src/routes/admin/brand-enrichment.ts:392). Today the admin PATCH commits a new house_domain with only domain-format validation + an audit-log row. A compromised admin can graft any brand into any paying parent's hierarchy. Long-term trust model question: should house_domain writes require either (a) WorkOS DNS verification of the child domain by the parent org, or (b) explicit admin acknowledgement on a separate route distinct from generic registry edits? The audit log is a detective control only.
  • LLM-output cross-check (server/src/services/brand-classifier.ts). The classifier's house_domain output is cross-checked against… nothing. Should we refuse to persist confidence='high' if the classifier's house_domain is not WorkOS-verified by any org? Or fall back to 'medium'? Either way is a policy call.
  • Re-promotion review — once a house_domain row is set to confidence='high', there's no review queue or re-validation step. Should hierarchy edges that affect a paying org's membership inheritance require admin review on promotion?

Labels

The repo does not have a security:disclosed label. Flagging here per the triage instruction: this PR is the disclosed fix for #3467.

Test plan

  • npx vitest run server/tests/unit/brand-db-house-domain-validation.test.ts — 10 passed
  • npx vitest run server/tests/unit/brand-classifier-tool-use.test.ts server/tests/unit/brand-claim-service.test.ts — 27 passed (no regressions on adjacent tests)
  • npx tsc --noEmit -p server/tsconfig.json — clean for the touched files (pre-existing @adcp/sdk resolution errors are unrelated)

The brand-hierarchy auto-link path in org-filters.ts walks
brands.house_domain and gates membership inheritance on
brand_manifest->'classification'->>'confidence' = 'high'. Every community
write surface accepted both fields as opaque JSON, so an attacker could
submit house_domain = paying-target.example plus brand_manifest with
classification.confidence='high', then sign in from the attacker domain
to inherit a WorkOS membership in the paying target.

Three bounded fixes at the DB layer in brand-db.ts:

1. classification.* is stripped from any caller-supplied brand_manifest
   and routed exclusively through a new typed
   UpsertDiscoveredBrandInput.classification field. The brand-classifier
   service is the only writer of trusted classification.

2. house_domain is canonicalized and validated on every write to
   upsertDiscoveredBrand/createDiscoveredBrand/editDiscoveredBrand
   (rejects control characters, malformed shapes, self-references).

3. edits preserve the prior trusted classification block so a
   refresh-logos edit doesn't silently drop the classifier's verdict.

Regression test exercises the hostile payload against all three write
methods. Architecture questions (long-term trust model for the
write-path) tracked separately as PR description follow-ups.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 68a9309 into main May 17, 2026
14 checks passed
@bokelley
bokelley deleted the fix/3467-validate-house-domain-write-path branch May 17, 2026 15:44
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.

security: validate brands.house_domain on write-path (block adversarial parent claims)

1 participant