Repository navigation
fix(registry): resolve ownership and badge checks through the registry identity key - #8350
Merged
Merged
Conversation
…y identity key The registry identity key folds a non-root trailing slash (#7830), so `…/mcp` and `…/mcp/` are one agent and every per-agent surface addresses it by the folded key. The ownership, badge and owner-credential predicates matched the stored `member_profiles.agents[].url` exactly, and the admin profile writer was still minting unfolded rows, so an owner who registered the other spelling was denied their own agent: no dashboard, no compliance refresh, badge fan-out revoking everything because the membership org "did not exist", and the owner's saved credentials ignored. Key `agents[].url` on `PUT /api/admin/member-profiles/:id`, preserving the registered spelling in `declared_url` like the other writers, and resolve the agent through the new shared `agentIdentityContainment` filter in every ownership, badge and owner-credential predicate. Org and role scoping are unchanged at every site, `declared_url` never decides identity, and authorization matching against a publisher's adagents.json stays spec-exact (#7829). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — server-only identity-fold refactor, no blocking or medium findings.
What I checked:
- No protocol surface touched: no
static/schemas/source/**,docs/reference/**,dist/**, task definitions, or changeset in scope.check-changeset-protocol-scopepasses, so no changeset is required. - Author team gate: no no-auto-approve team match.
- Gated paths:
gated_paths: false— row 2 does not apply. - High-risk flag is true only via
(modified)entries onserver/src/routes/member-profiles.tsandserver/src/routes/registry-api.ts. Per the change-kind rules, modifications are presumed safe when the reviewer finds no medium-or-higher concerns — and here there are none. Row 5 does not fire (no medium findings). - Reviewer verified placeholder arithmetic at all 11 call sites (no off-by-one), org/membership scoping preserved verbatim at every folded query,
canonicalizeAgentUrl === registryAgentUrlKey, SAFE_COLUMN regex gates the only interpolated string, and behavior changes #1–#3 are deliberate, documented, and test-covered.
No Critical/High/Medium findings. Rows 1–8 do not fire; falls through to row 9 → approve.
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.
Problem
registryAgentUrlKeyfolds a non-root trailing slash (#7830), so…/mcpand…/mcp/are one agent, and every per-agent surface addresses that agent bythe folded key.
member_profiles.agents[].urlis classified IDENTITY by thekey's own doc comment — but its readers matched the stored URL exactly, and
the admin profile writer was still minting unfolded rows. An owner who
registered the other spelling was therefore denied their own agent:
agent-ownership.ts),membershipOrgIdundefined in badge fan-out, which makesprocessAgentBadgesrevoke every badge the agent has (
badge-issuance.ts),authorization_changedfrom the locked re-check inselectGradingProfile(
verification-profile-db.ts),401'd (
compliance-db.ts,agent-context-db.ts).#8325 fixed the notification reader and deliberately left these alone, because
widening an authorization check with an identity-fold helper is what
registryAgentUrlKey's doc comment forbids — until the writer stops producingunfolded rows. This closes that loop: the writer first, then the readers.
Writer
PUT /api/admin/member-profiles/:idnow keysagents[].urland preserves theregistered spelling in
declared_url, likeroutes/member-agents.tsandroutes/admin/agents.ts. A supplieddeclared_urlis honoured only when itkeys back to the same agent (the rule
gateAgentVisibilityForCalleralreadyapplies) and rejected with 400 otherwise —
declared_urlis whatAUTHORIZATION matching compares against (#7829), and a quiet substitution on
that field leaves the admin believing they set something they did not.
Two newly returned 400s on this admin route, both deliberate: an entry
without a string
url, and a new entry whose URL the key rejects. A URL thekey rejects that the profile already holds byte for byte is grandfathered,
because this handler is the last-resort repair surface for exactly the legacy
rows this issue is about.
The two bulk member writers (
POST/PUT /api/me/member-profile) keyedagents[].urlbut never originated adeclared_url, so a member registering…/mcp/through them lost a spec-exact authorization that the same bytesthrough
POST /api/me/agentskept. Three surfaces, two authorization outcomesfor one input — fixed here too, since the admin comment would otherwise claim a
parity that did not exist.
Readers
New
server/src/db/agent-identity-match.ts—agentIdentityContainment(column, agentUrl, firstPlaceholder)builds theparenthesized
ORof@> $n::jsonbcontainment tests, one per spelling fromregistryAgentUrlKeySpellings(#8325, trailing-slash fold only). One@>perspelling, so the GIN index on
member_profiles.agents(migration 014) stillserves it; the SQL text is assembled from placeholder indexes only, and the
column reference is validated against a bare-identifier regex.
params[0]isdocumented as the pre-fold payload so a one-row query can still prefer it.
Folded, with org scoping unchanged at every site:
services/agent-ownership.tsservices/badge-issuance.tsdb/verification-profile-db.tsdb/compliance-db.tshasOwnerAuth,resolveOwnerAuth, both public-effect gatesservices/compliance-refresh-authorization.tsowner_testre-checkroutes/registry-api.tsdb/agent-context-db.tsnotifications/compliance.tsThe last four are not in the issue's list but are the same predicate and had to
move with it: the compliance-refresh and registry-admin checks are the locked
re-checks behind gates this PR folds, so leaving them exact would let an
owner pass admission and then fail mid-write;
agent-context-dbis the twin ofcompliance-db.resolveOwnerAuth; and leaving #8325's inline copy would be twospellings of one predicate drifting apart.
scripts/backfill-owner-test-history.tsis deliberately not folded — abackfill that widens its eligibility relabels history, and a row it misses
stays an ordinary test row, which is the safe direction. Now documented in that
file.
What the fold does not widen
workos_organization_id/organization_membershipspredicate verbatim. The fold changes whichspelling of one agent a profile may hold, never which profile a user may
reach. A member gains nothing over an agent only another org registered.
declared_url. Every containment payload keys onurlalone, and thetwo
jsonb_array_elementsreads projectagent->>'url'. The spec-exactAUTHORIZATION spelling can never decide identity.
validator.ts,find_agents_for_property,/publishers,/domainsand the directory reads are untouched and still gothrough
declaredAgentUrl.resolveOwnerAuthstill decrypts with theorganization_idof the row the ciphertext came from, and the join still pins credential and
profile to one org.
Three behaviour changes worth naming
findSoleOwnerOrgForUsercan now fail closed where it previouslyanswered. A user in two orgs that register the same agent under different
spellings used to be disambiguated by spelling — which is not a real
distinction — and now hits the documented "multiple matches fail closed"
path, because choosing either tenant would select the wrong encryption
context. The explicit-org path (
resolveOwnerOrgForUserwith?org=) stillanswers. Covered by an integration test.
membership_org_idcannot move. The membership-org query picks onerow and stamps it on every badge, and two orgs can co-claim one agent, so it
now orders a profile holding the key itself ahead of one reached only through
the fold;
mp.created_atbreaks the tie within each group exactly as before.public-effect gates ask "did an owner list THIS agent publicly" by identity,
so demoting the indexed row while a sibling spelling stayed
publicwouldhave made an owner's "make it private" not take effect where it matters.
applyAgentVisibilitynow flips every entry that is the same agent.findOwnedAgentVisibilitycan also match more than one row now, so it ordersmost-permissive-first instead of leaving
LIMIT 1to the planner — the sameanswer
isAgentPublicgives, which keeps the caller's public-event decisionself-consistent.
Tests
Every one of these fails if the fold is removed (verified by reverting the
eight changed source files to
origin/mainand rerunning: 15 unit and 12integration assertions go red, across 9 of the 11 files).
server/tests/unit/agent-identity-match.test.ts— the filter's contract:placeholder arithmetic at an offset, parenthesization,
params[0]ordering,url-only payloads, the unkeyable fallback, and the column guard.server/tests/integration/agent-ownership-url-key.test.ts— the real SQL.All five ownership helpers in both spelling directions; a second org
co-claiming the other spelling gaining nothing inside the first org's
profile; a user in neither org getting nothing; a prefix-sharing neighbour
never reached; a
declared_url-only profile never resolving ownership; theowner/adminrole requirement intact; badge membership-org resolution andits org-preference ordering; owner credentials in both directions and the
cross-org negative; both public-effect gates.
server/tests/integration/verification-profile-selection-migration.test.ts—the locked re-check authorizes through the identity key, and a
declared_urlpointing at the caller's agent authorizes nothing.
server/tests/unit/compliance-refresh-authorization.test.tsandregistry-badge-routes.test.ts— the two remaining call sites' param shapes(the only
firstPlaceholder: 3site, and the only unqualified-column site).server/tests/unit/member-profile-admin-agent-url-key.test.ts— the adminwriter: keying,
declared_urlround-trip, the 400s, and grandfathering.server/tests/integration/agent-visibility-e2e.test.ts—declared_urlfromthe bulk member PUT, and the identity-scoped visibility flip.
server/tests/unit/badge-issuance-owner-url-key.test.ts, plus updates toagent-ownership.test.tsandagent-context-url-canonicalization.test.ts.Notes for reviewers
node scripts/check-changeset-protocol-scope.cjs origin/mainpasses.matrix skipped itself (no training-agent or compliance source changed).
code-reviewerandsecurity-reviewersubagents. Every finding is fixed above or answered here; the two the
security reviewer rated Medium (the member writers' missing
declared_url,and
ac.agent_urlstill bound to one spelling in the owner-auth reads) areboth fixed rather than deferred.
relative to the member paths (no query-string rejection, no tier gate on
visibility, no unknown-
typedrop). Pre-existing, orthogonal to keying, andcalled out in the code comment so the next reader does not assume parity.
Closes #8322
🤖 Generated with Claude Code
Open workspace in Conductor