Repository navigation
fix(security): validate brands.house_domain on write-path (#3467) - #4613
Merged
Merged
Conversation
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]>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tswalksbrands.house_domainand gates membership inheritance onbrand_manifest->'classification'->>'confidence' = 'high'. Every community write surface (save_brandMCP tool,editDiscoveredBrand,upsertDiscoveredBrand) accepted both fields as opaque JSON.Pre-fix attack:
Then sign in from
@attacker.example. The recursive org-chain join inorg-filters.tsmatcheshouse_domain = paying-target.exampleAND the JSONB confidence gate, and (if the paying target opted intoauto_provision_brand_hierarchy_children)autoLinkByVerifiedDomainissues the attacker a WorkOS membership in the paying target.The strongest current guard is that
auto_provision_brand_hierarchy_childrendefaults tofalse. 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.tsso every caller (MCP, HTTP, Addie tools, admin routes, crawler) inherits the same enforcement:brand_manifest—classification.*is stripped from any caller-supplied manifest. Trusted classification flows exclusively through a new typedUpsertDiscoveredBrandInput.classificationfield that only the brand-classifier service (brand-enrichment.ts) populates.house_domainon every write — canonicalized viacanonicalizeBrandDomain, validated viaassertValidBrandDomain, rejects control characters (NUL/CR/LF) and self-references. Applied toupsertDiscoveredBrand,createDiscoveredBrand,editDiscoveredBrand.confidence='high'to'low'via an edit).Regression test in
server/tests/unit/brand-db-house-domain-validation.test.tsexercises 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:
server/src/routes/admin/brand-enrichment.ts:392). Today the admin PATCH commits a newhouse_domainwith 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: shouldhouse_domainwrites 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.server/src/services/brand-classifier.ts). The classifier'shouse_domainoutput is cross-checked against… nothing. Should we refuse to persistconfidence='high'if the classifier'shouse_domainis not WorkOS-verified by any org? Or fall back to'medium'? Either way is a policy call.house_domainrow is set toconfidence='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:disclosedlabel. 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 passednpx 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/sdkresolution errors are unrelated)