Skip to content

fix(registry): resolve ownership and badge checks through the registry identity key - #8350

Merged
bokelley merged 1 commit into
mainfrom
conductor/issue-8322
Oct 19, 2026
Merged

bokelley merged 1 commit into
mainfrom
conductor/issue-8322

Conversation

@bokelley

@bokelley bokelley commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

registryAgentUrlKey folds a non-root trailing slash (#7830), so …/mcp and
…/mcp/ are one agent, and every per-agent surface addresses that agent by
the folded key. member_profiles.agents[].url is classified IDENTITY by the
key'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:

  • no dashboard, no compliance refresh, no OAuth context (agent-ownership.ts),
  • membershipOrgId undefined in badge fan-out, which makes processAgentBadges
    revoke every badge the agent has (badge-issuance.ts),
  • authorization_changed from the locked re-check in selectGradingProfile
    (verification-profile-db.ts),
  • the owner's saved credentials ignored, so the probe went out anonymous and
    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 producing
unfolded rows. This closes that loop: the writer first, then the readers.

Writer

PUT /api/admin/member-profiles/:id now keys agents[].url and preserves the
registered spelling in declared_url, like routes/member-agents.ts and
routes/admin/agents.ts. A supplied declared_url is honoured only when it
keys back to the same agent (the rule gateAgentVisibilityForCaller already
applies) and rejected with 400 otherwise — declared_url is what
AUTHORIZATION 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 the
key 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) keyed
agents[].url but never originated a declared_url, so a member registering
…/mcp/ through them lost a spec-exact authorization that the same bytes
through POST /api/me/agents kept. Three surfaces, two authorization outcomes
for 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 the
parenthesized OR of @> $n::jsonb containment tests, one per spelling from
registryAgentUrlKeySpellings (#8325, trailing-slash fold only). One @> per
spelling, so the GIN index on member_profiles.agents (migration 014) still
serves it; the SQL text is assembled from placeholder indexes only, and the
column reference is validated against a bare-identifier regex. params[0] is
documented as the pre-fold payload so a one-row query can still prefer it.

Folded, with org scoping unchanged at every site:

File Predicate
services/agent-ownership.ts all five helpers
services/badge-issuance.ts membership-org resolution
db/verification-profile-db.ts locked ownership/role re-check
db/compliance-db.ts hasOwnerAuth, resolveOwnerAuth, both public-effect gates
services/compliance-refresh-authorization.ts locked owner_test re-check
routes/registry-api.ts registry-admin override ownership check
db/agent-context-db.ts crawler owner-credential lookup
notifications/compliance.ts #8325's hand-rolled copy, now the shared helper

The 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-db is the twin of
compliance-db.resolveOwnerAuth; and leaving #8325's inline copy would be two
spellings of one predicate drifting apart.

scripts/backfill-owner-test-history.ts is deliberately not folded — a
backfill 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

  • Org scoping. Every query keeps its workos_organization_id /
    organization_memberships predicate verbatim. The fold changes which
    spelling 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 on url alone, and the
    two jsonb_array_elements reads project agent->>'url'. The spec-exact
    AUTHORIZATION spelling can never decide identity.
  • Authorization matching. validator.ts, find_agents_for_property,
    /publishers, /domains and the directory reads are untouched and still go
    through declaredAgentUrl.
  • Credentials. resolveOwnerAuth still decrypts with the organization_id
    of the row the ciphertext came from, and the join still pins credential and
    profile to one org.

Three behaviour changes worth naming

  1. findSoleOwnerOrgForUser can now fail closed where it previously
    answered.
    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 (resolveOwnerOrgForUser with ?org=) still
    answers. Covered by an integration test.
  2. Badge membership_org_id cannot move. The membership-org query picks one
    row 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_at breaks the tie within each group exactly as before.
  3. Agent visibility is now flipped by identity, not by array index. The
    public-effect gates ask "did an owner list THIS agent publicly" by identity,
    so demoting the indexed row while a sibling spelling stayed public would
    have made an owner's "make it private" not take effect where it matters.
    applyAgentVisibility now flips every entry that is the same agent.

findOwnedAgentVisibility can also match more than one row now, so it orders
most-permissive-first instead of leaving LIMIT 1 to the planner — the same
answer isAgentPublic gives, which keeps the caller's public-event decision
self-consistent.

Tests

Every one of these fails if the fold is removed (verified by reverting the
eight changed source files to origin/main and rerunning: 15 unit and 12
integration 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; the
    owner/admin role requirement intact; badge membership-org resolution and
    its 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_url
    pointing at the caller's agent authorizes nothing.
  • server/tests/unit/compliance-refresh-authorization.test.ts and
    registry-badge-routes.test.ts — the two remaining call sites' param shapes
    (the only firstPlaceholder: 3 site, and the only unqualified-column site).
  • server/tests/unit/member-profile-admin-agent-url-key.test.ts — the admin
    writer: keying, declared_url round-trip, the 400s, and grandfathering.
  • server/tests/integration/agent-visibility-e2e.test.ts — declared_url from
    the bulk member PUT, and the identity-scoped visibility flip.
  • server/tests/unit/badge-issuance-owner-url-key.test.ts, plus updates to
    agent-ownership.test.ts and agent-context-url-canonicalization.test.ts.

Notes for reviewers

  • No changeset. Server-only; node scripts/check-changeset-protocol-scope.cjs origin/main passes.
  • No hooks skipped. Full pre-commit suite ran; the pre-push storyboard
    matrix skipped itself (no training-agent or compliance source changed).
  • Reviewed before opening by the code-reviewer and security-reviewer
    subagents. Every finding is fixed above or answered here; the two the
    security reviewer rated Medium (the member writers' missing declared_url,
    and ac.agent_url still bound to one spelling in the owner-auth reads) are
    both fixed rather than deferred.
  • Still not folded, deliberately: the admin surface's other permissiveness
    relative to the member paths (no query-string rejection, no tier gate on
    visibility, no unknown-type drop). Pre-existing, orthogonal to keying, and
    called out in the code comment so the next reader does not assume parity.

Closes #8322

🤖 Generated with Claude Code


Open workspace in Conductor

…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]>

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-scope passes, 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 on server/src/routes/member-profiles.ts and server/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.

@bokelley
bokelley merged commit ad182b1 into main Oct 19, 2026
35 checks passed
@bokelley
bokelley deleted the conductor/issue-8322 branch October 19, 2026 22:43
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.

Agent-URL identity reads match the stored agents[].url raw, and the admin profile writer stores it unkeyed

1 participant