Skip to content

fix(registry): bind the registry-review verdict to the submitter and fail safe - #8337

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

bokelley merged 1 commit into
mainfrom
conductor/issue-8326

Conversation

@bokelley

@bokelley bokelley commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #8326.

Two things #8330 deliberately left out, plus three bugs the security review turned up on the way.

1. The registry-review prompt boundary and its fail-open posture

server/src/addie/mcp/registry-review.ts builds an LLM prompt out of content a member just submitted and acts on the verdict: ok publishes the record, malicious bans the submitter and deletes or reverts the record. The prompt embedded the edit summary and the raw snapshot diff unfenced, and both the parse-failure path and the catch returned { verdict: 'ok' }.

The issue asked for three properties. Each is now a structural guarantee rather than a prompt instruction:

A forced malicious can only act on the submitter who forced it. The prompt now carries only the submitter's own text. The big one here is the change list: summarizeChanges renders previous field values by shape (previous value: text, 812 chars (not quoted)) and never quotes them, because on an edit the previous revision may be a different member's work and the ban lands on the current editor. describeChangeShape buys back the correction-vs-replacement signal that costs, out of a fixed five-phrase alphabet an earlier editor cannot steer.

A verdict we don't trust fails safe. New harness-only needs_human_review: unparseable output, an out-of-contract verdict, a verdict with no reason, a failed or unconfigured model call. It approves nothing, bans nothing, reverts nothing, and posts to the moderator channel. The model's vocabulary is unchanged at three verdicts — a model that claims needs_human_review is out of contract and its reason is dropped.

Submitted content is delimited. One <untrusted_proposer_input> fence per prompt via wrapUntrustedInput, the boundary rule stated on both sides of it, and every labelled line flattened — the tags stop instructions, they don't stop a submitter from forging their own Changes: list inside the fence.

Two more holds the reviews argued for, both in applyReviewIntegrity:

  • A submission too large to fit the prompt is never auto-approved. Otherwise "pad the first 12 KB, bury the spam past the cap" is a route to publication.
  • Neither is one that tried to close the boundary tag. malicious still acts in both cases: everything the model did see was written by this submitter, so acting on it stays attributable. Only publication is held back.

Plus:

  • Service identities are never auto-banned. enhanceProperty defaults its submitter to system:addie, so a malicious verdict on a row some other member asked Addie to create would have banned Addie's own registry identity. The record is still removed — that acts on the content, not on a third party.
  • notifyAddieReview posts to the channel without a thread when a human has to act. enhanceProperty never opens a card, and a pending record is locked against further edits (Cannot edit brand pending review), so a silent needs_human_review would strand a member's submission with nobody told.
  • The model's reason is capped at 500 chars before it reaches a stored ban row.
  • Verdicts are matched case- and whitespace-insensitively, so an ordinary "Ok" is an approval rather than silent moderator work.
  • A non-string edit_summary (the MCP server does not validate arguments against the advertised schema) no longer throws out of the prompt builder.

Three bugs found while establishing the above

These are pre-existing, but each one is a counterexample to the invariant this PR is claiming, so they're fixed here rather than filed.

  1. The MCP edit path read the wrong revision. editDiscoveredBrand / editCommunityProperty snapshot the row before applying the edit, so revision N is the pre-edit state. http.ts passes getBrandRevision(domain, revision_number); mcp-tools.ts passed revision_number - 1 — the state before the previous member's edit. Every field that member changed and this one left alone then appeared in the review prompt as this member's submission, with their text in it, under a verdict that bans this member. server/tests/integration/registry-review-editor-attribution.test.ts pins it against the real revision machinery.
  2. Auto-revert rolled back one revision too far, discarding the previous member's edit along with the vandalism. Undoing edit N restores revision N.
  3. A malicious verdict on a record's first edit did nothing at all — rollbackTo = revision_number - 1 was 0, and the ban was nested inside the rollbackTo >= 1 guard. Every Brandfetch-enriched brand has zero revisions until someone edits it, so the first vandalism of any enriched brand was unbannable and unrevertable. The ban is also out of the revert's try now: a deadlock on the rollback should not hand the editor a free pass.

action_taken in the moderator thread reports what actually happened rather than what we set out to do — a failed revert that still reads "Edit reverted" is how live vandalism gets closed as handled.

2. The five remaining local Slack escapers

All five escaped & < > and stopped there, so none flattened a newline: a member- or model-authored org name, event title, display name or digest headline could still forge an extra line in a message the reader treats as platform copy.

org-group-dm.ts, weekly-digest.ts, announcement-trigger.ts, event-recap-nudge.ts, welcome-social-posts.ts now use utils/slack-escape.ts, along with the three modules that imported the one escaper that was exported (workos-webhooks.ts, auto-provision-digest.ts, seat-request-reminders.ts).

  • New sanitizeSlackLiteral. announcement-trigger.ts was the one escaper that defused bare-URL auto-linking, and sanitizeSlackLine deliberately doesn't — a WorkOS org renamed to Acme https://evil.example Co is still a clickable attacker destination on a card editorial reads as ours. Rather than let that regress, the strictest form moved into the shared module.
  • weekly-digest.ts splits by surface. Everything the renderer composes — headlines, names, labels, bullets, and the one-paragraph fields openingTake / specInsight.body, which the email render already collapses into a single <p> — is flattened. Author-written markdown (editor's note, pasted content, custom sections) keeps its line breaks, because there the line structure is the formatting. Those two paragraph fields are also now capped under Slack's 3000-char section limit; they were pushed as their own block, so an over-long one would have been rejected as invalid_blocks and lost the whole post.
  • Digest link targets are checked and the link dropped when unsafe, which the old escape-only pass could not do.
  • Two Slack text fallbacks were still raw (workos-webhooks.ts, auto-provision-digest.ts) while the block body next to them was sanitized. text is what Slack renders in the notification preview, which is where a forged line is most convincing.

Tests

All new tests fail if the corresponding fix is reverted — verified by mutation, including the revision off-by-one.

  • server/tests/unit/registry-review-prompt-boundary.test.ts — 37 cases: injection payloads that try to close the fence, forge a Changes: list, or force either verdict; the prior-editor marker never reaching the prompt; every inconclusive outcome on both entry points; the truncation and tampering holds; the service-identity ban guard; first-edit revert; failed-revert reporting.
  • server/tests/integration/registry-review-editor-attribution.test.ts — the revision off-by-one, against Postgres.
  • server/tests/unit/slack-escaper-sweep.test.ts — the five swept surfaces, shape-based like slack-notification-builder-sweep.test.ts.
  • Additions to slack-escape.test.ts for sanitizeSlackLiteral, and one pinning that sanitizeSlackLine still passes *bold* through.
  • The describe("escapeSlackMrkdwn") block in seat-lifecycle-notifications.test.ts is gone with the function; slack-escape.test.ts covers the same behaviour.

No changeset — server/Addie-only, and scripts/check-changeset-protocol-scope.cjs agrees.

Notes for review

  • The fail-safe changes operational behaviour. An Anthropic outage, or a deployment without ANTHROPIC_API_KEY, now leaves new community records pending instead of auto-approving them. That is the point, but it means the moderator channel is the queue — there is still no admin listing of pending registry records, which is worth its own issue if this starts firing.
  • Shape-only prior values cost the reviewer some context, and describeChangeShape only partly repays it. Replacing an accurate description with a plausible but false one of similar length is harder for the model to see now. The trade is deliberate: the alternative is another member's text in a prompt whose output bans this one.
  • One invariant has an exception, documented in the file header. enhanceProperty builds its snapshot from a model's reading of a third-party domain, which the triggering member did not author. The system:addie ban guard is what holds there. If enhanceProperty ever attributes rows to a real member, the content invariant has to be re-established first.
  • sanitizeSlackLiteral wants a line in the playbook's helper list. That list is added by docs(agents): record the Slack output convention in the playbook #8331, which is still open and behind the .agents/** CODEOWNERS gate — the bullet is in a comment there rather than in a conflicting PR against an unmerged section.
  • Reviewed by the security-reviewer, prompt-engineer, and code-reviewer agents before opening. Every finding is fixed above except the two trade-offs called out in these notes.

🤖 Generated with Claude Code


Open workspace in Conductor

…fail safe

Two things #8330 left out, plus three bugs found establishing the first.

## The registry-review prompt boundary

The registry reviewer builds an LLM prompt out of content a member just
submitted and acts on the verdict: `ok` publishes the record, `malicious`
bans the submitter and deletes or reverts their work. The prompt embedded
the edit summary and the raw snapshot diff unfenced, and both the
parse-failure path and the `catch` returned `{ verdict: 'ok' }`.

Make the three properties #8326 asks for structural rather than
instructional:

- Only the submitter's own content reaches the prompt. Previous field
  values are rendered by shape and never quoted, because on an edit the
  previous revision may be a different member's work while the ban lands
  on the current editor. `describeChangeShape` buys back the
  correction-vs-replacement signal out of a fixed alphabet.
- A verdict we don't trust fails safe. New harness-only
  `needs_human_review` for unparseable output, an out-of-contract
  verdict, or a failed model call: approves nothing, bans nothing,
  reverts nothing, posts to the moderator channel. A submission too
  large to fit the prompt, or one that tried to close the boundary tag,
  is never auto-approved either.
- Submitted content is fenced in one `<untrusted_proposer_input>` block
  with the boundary rule on both sides of it, and every labelled line is
  flattened so it cannot forge structure inside the fence.

Also: never auto-ban a `system:` principal (`enhanceProperty` attributes
its rows to `system:addie`); post to the moderator channel when there is
no thread, since a pending record is locked and `enhanceProperty` never
opens a card; cap the model-authored ban reason.

Three pre-existing bugs that are counterexamples to the above, so fixed
here: the MCP edit path diffed against revision N-1 rather than N and
attributed the previous member's text to this one; auto-revert rolled
back one revision too far; and a `malicious` verdict on a record's first
edit did nothing at all.

## The five remaining local Slack escapers

`org-group-dm.ts`, `weekly-digest.ts`, `announcement-trigger.ts`,
`event-recap-nudge.ts` and `welcome-social-posts.ts` all escaped
`& < >` and stopped there, so none flattened a newline — an org name,
event title or generated headline could still forge an extra line in a
message the reader treats as platform copy. All five now use
`utils/slack-escape.ts`, along with the three modules that imported the
one escaper that was exported.

`sanitizeSlackLiteral` is new: `announcement-trigger.ts` was the only one
that defused bare-URL auto-linking, so the strictest form moved into the
shared module rather than regress. `weekly-digest.ts` splits by surface —
composed lines are flattened, author-written markdown keeps its line
breaks — and its link targets are now checked rather than escaped.

Closes #8326.

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 — clean hardening PR (#8337) for adcp#8326 with no blocking or medium findings.

What was checked:

  • 18 files, all server/Addie/operational code. No static/schemas/source/**, task defs, normative docs/reference/**, or dist/** artifacts touched — changeset, oneOf-discriminator, and released-artifact-immutability gates are N/A.
  • registry-review.ts (~400 diff lines): fail-closed verdict model (callReview → needs_human_review on parse/error/no-key; applyReviewIntegrity holds ok/suspicious on truncated/boundary-tampered views, L385-398), shape-only rendering of prior revisions, <untrusted_proposer_input> fence, and bannable-submitter guard all correct. neutralizeUntrustedTags only rewrites < inside tag sequences, so no boundaryTampered false-positives.
  • Load-bearing off-by-one fix verified: mcp-tools.ts:1760/1927 now use getBrandRevision(domain, revision_number) and rollbackTo = edit.revision_number, matching http.ts:3964/4457 and pre-edit snapshot semantics. Covered by integration + unit tests against real Postgres including the N=1 first-edit case.
  • Slack-escape consolidation across five surfaces defuses forged lines/links/mentions, with tests.
  • Review runs remain fire-and-forget (pre-existing) but now fail safe rather than fail-open.

Decision trace: No critical/high/medium findings (rows 1, 4-6, 8 don't fire). gated_paths is false (row 2 N/A). high_risk is true but all reasons are (modified) with no medium finding (rows 3, 5 don't fire). No no-auto-approve team match (row 7 N/A). No prior decision. Falls through to row 9 → approve.

@bokelley
bokelley merged commit d1ea874 into main Oct 19, 2026
35 checks passed
@bokelley
bokelley deleted the conductor/issue-8326 branch October 19, 2026 13:21
bokelley added a commit that referenced this pull request Oct 19, 2026
…view (#8349)

* feat(admin): queue and backlog signal for registry records pending review

Since #8337 registry review fails safe: an unparseable verdict, an
out-of-contract verdict, or a failed model call (an Anthropic outage, or
a deployment with no ANTHROPIC_API_KEY) leaves community brands and
properties pending instead of publishing them. The moderator Slack
channel was the only queue, so a provider outage could build a backlog
behind a message nobody re-read.

- `registry_review_queue` (migration 627) records every outcome that
  leaves a decision for a human. Edit rows carry the revision #8337
  fixed — revision N restores the state before edit N.
- `/admin/registry-review` plus `/api/admin/registry-review/*`: the
  queue (record, revision, submitter, verdict/reason, age), approve /
  reject / revert, each recorded with the moderator identity.
- Backlog signal (count + oldest age) in the admin view, in a daily
  digest to the moderator channel, and as the
  `registry-review-queue-drained` operational diagnostic.

Closes #8338

* fix(admin): keep in-flight domain claims out of the registry review queue

`issueDomainClaim` parks a bare `hosted_properties` row — empty
adagents.json, a claim token, no creator and no revision — at
`review_status = 'pending'` while a publisher proves origin control.
The queue read `review_status` alone, so that row appeared as a
community submission: approving it would have published an empty
document as the publisher's own, and rejecting it would have deleted
an in-flight claim and stranded its token.

A pending row is a submission only when somebody submitted it. Both
real paths leave a submitter — `createCommunityProperty` and
`createDiscoveredBrand` write revision 1, `enhanceProperty` sets
`created_by_user_id` — and a claim row has neither. The listing, the
backlog count, the action guard and the diagnostic now all read that
one predicate from `registry-review-queue-db.ts`.

* fix(admin): make registry moderation actions atomic and record-scoped

Addresses the security, code and internal-tooling reviews of the queue.

Correctness of the actions:

- A revert is a decision about the record, not about one row. An
  inconclusive verdict bans nobody and leaves the record editable, so
  one member can stack edits 5, 6 and 7 and leave three open items.
  Restoring revision 5 undoes all three — and "reverting" item 7
  afterwards would have put 5 and 6 straight back, emptied the queue
  and zeroed the backlog. Revert now rolls back to the earliest open
  revision and closes every item it covered.
- Claiming is no longer resolving. The claim takes `claimed_at` /
  `claimed_by_user_id`; only a completed action writes `resolved_at`.
  A crash between the two now leaves the item in the queue instead of
  marking it reverted by a revert that never ran. Stale claims expire.
- Approve and reject carry the `review_status = 'pending'` predicate
  into the write (`onlyIfPending`). The prior read-then-write let a
  review that finished in between turn "reject a pending submission"
  into "delete a live registry record".
- `rollbackProperty` refuses authoritative and pending records, as
  `rollbackBrand` already did. A queued revert target can outlive the
  record's community status.
- Record decisions close only `new_record` items, never a flagged edit
  the moderator never saw.
- A malicious edit with no revision to revert to now queues with a null
  revision and no revert action, instead of vanishing from the queue
  while Slack says a human is needed.

Usability of the view:

- The queue returns the submitted record (brand fields and manifest, or
  adagents.json), capped and rendered in a collapsible block. A pending
  record is hidden from the public viewer, so this was the one thing a
  moderator could not see before approving it. Read from the row, not
  from a revision snapshot, which for a property carries its claim and
  verification tokens.
- The page paginates and says "showing N of M"; a failed load no longer
  leaves stale backlog tiles standing.
- The moderator channel distinguishes a published record from a kept
  edit, and says when a revert covered stacked edits.
- A suspicious new record now reports that it was published anyway.

The operational diagnostic is one aggregate violation reading the same
backlog as the page and the digest, rather than one per stale item: the
outage it exists to catch is exactly when per-item findings would bury
the billing and directory violations the report is opened for.

* chore(admin): drop the unused single-item queue read helper

* fix(admin): make a flagged record one decision, and bound the revert in SQL

Second round of review findings.

- **Stacked edits are one row.** The queue collapsed three flagged
  edits on a record into three rows with their own buttons, which
  invited a moderator to keep edit 7 and then revert edit 5 —
  discarding the edit they had just kept, with no row left to say so.
  The listing now returns one row per record, carrying the earliest
  open revision and a count of what it stands for, and both actions
  are record-scoped.
- **The revert's resolve set comes from the rollback.** It was computed
  from a list read beforehand, so an edit landing in that window stayed
  open holding a revert target that now restores the vandalism. The
  rollback returns the revision it created; every open edit below it is
  closed in one statement. That also removes a filter that could never
  exclude anything.
- **The claim is honoured at resolve time.** `resolveRegistryReviewItem`
  refuses when somebody else holds the item, so a lapsed hold cannot
  write one moderator's verdict over another's.
- **Vandalism nobody could undo is `dismissed`, not `approved`.** An
  edit with no revision to restore has no revert; recording "keep" as
  an approval would put a moderator's name behind content they only
  failed to roll back.
- The confirm dialog and the success message say what the server
  actually does — which revision was restored, and how many queued
  edits the decision closed.
- Releasing a claim can no longer turn an intended 409 into a 500, and
  a failed queue write after a successful rollback no longer reports
  the rollback as failed.
- `/api/properties/hosted/:domain/rollback` maps the new authoritative
  and pending refusals to 403 instead of 500.

* fix(admin): show every edit a collapsed decision covers, and bound its target

Third round of review findings, all on the collapsed flagged-edit row.

- **The card showed one edit's evidence and asked for a verdict on all
  of them.** Land a benign edit first and the payload second and the
  row rendered the harmless summary over a "keep" button that approved
  both. The payload now carries every covered edit — revision,
  submitter, summary, verdict, reason — and the page renders them all.
- **An edit reviewed after a revert named a poisoned revert target.**
  The review is asynchronous, so its queue row can land after a
  moderator already rolled the record back; revision N then snapshots
  the pre-revert state and "undo edit N" would put the vandalism
  straight back. `recordRegistryReviewOutcome` drops the revert target
  when a rollback has landed above the revision, and the revert path
  re-checks before acting.
- **Keeping now honours a live claim**, all-or-nothing, and 409s. A
  revert is a fact about the record, so it may close items others
  hold; keeping is a decision *not* to act and can race one that does,
  which would have recorded "kept" over a rollback in flight. The page
  disables the buttons on a row somebody else is working.
- **The backlog counts decisions, not rows**, so the header, the
  pager, the digest and the diagnostic all report the number the queue
  actually lists. "Load more" is driven by whether the last page came
  back full.
- Dropped `resolveRegistryReviewItem`, which no longer had a caller.
- `api-key-widget-containment` mocks the new admin router, as it does
  every other one.

* fix(admin): put the revert's rollback guard inside the transaction

Last two findings from the security review.

- Two moderators on one record could both clear the route's pre-check
  — reviews for edits 4 and 5 race, so items can arrive out of
  revision order — and the loser's rollback would then restore a
  revision above the winner's, putting the undone edits back. The
  check moves inside `rollbackBrand` / `rollbackProperty` behind the
  row lock as an opt-in `onlyIfNoRollbackSince`, so the pre-check is
  the friendly error and the transaction is the boundary. The loser
  now gets a 409.
- An item the revert refuses could only be cleared as `approved`,
  putting a moderator's name behind vandalism that was in fact
  already undone. Keeping now consults the same predicate and records
  `dismissed`.
- A covered edit with no revision rendered as "revision 0", because
  `Number(null)` is 0.
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.

Finish the Slack-output sweep: remaining local escapers and the registry-review prompt boundary

1 participant