Repository navigation
fix(labeler): reject an emergency retract with no active label (W9.6 follow-up) - #2029
Conversation
A takedown/publisher-compromised retract now pre-checks that the target positive label is currently in effect (getActiveLabelState winner exists and active) before signing. An absent, already-negated, or expired label is a 404 NO_ACTIVE_LABEL — no no-op negation is signed and no operational event fires for a label that was never live. Pure read after the role and ceremony gates, before any commit. Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
|
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 1743746 | Jul 14 2026, 05:41 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 1743746 | Jul 14 2026, 05:41 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 1743746 | Jul 14 2026, 05:41 AM |
There was a problem hiding this comment.
Approach
This is the right change, solving the right problem. The W9.6 emergency-retract endpoints previously signed a no-op neg:true label and emitted a high-severity operational event for a takedown that was never live, returning 200. Adding a pre-check that the target positive label is currently in effect before signing is a sound, minimal hardening that fits the existing guard-then-sign-then-commit shape of runEmergencyAction. The fix is correctly scoped to the two emergency retract endpoints (handler + tests only; nothing frozen touched), and the "TDD for bugs" convention is honored with a reproducing test for every subject/label combination.
What I checked
- Guard semantics (
assertRetractableLabel). It reads the samegetActiveLabelStatestream winner the console and XRPC clients see, keyed by(src = labelerDid, uri, cid: ""), and rejects unlesswinners.get(val)exists and.activeis true. I verified against the implementation thatactiverequiresneg === 0,applicable(row.cid === null || row.cid === input.cid), and unexpired, and that the map's last-write-wins iteration yields the highest-sequence winner. The policy fixture confirms both!takedownandpublisher-compromisedarecidRule: forbiddenon every subject kind they grantadminfor, so emergency labels are always stored withcid NULL→cid: ""always matches via therow.cid === nullbranch. The!-prefixedvalis stored verbatim and looked up verbatim. No false-positive-vs-console divergence: the guard reads through the samedeps.dbbinding the console display uses. - Ordering / zero side effects. The guard runs after
guardMutation(role gate → ceremony →assertAdminIssuable) and beforecreateSigner/prepareManualLabelIssuance/commitMutation. A reviewer still gets 403 and a wrong ceremony/intent still gets 400 before the 404. On reject, no signer is created and nooperator_actions/issued_labels/operational_events/notification_outboxrow is written, and no deferred work is scheduled (theif (neg)read precedesdeps.defer). Verified. - Replay path.
guardMutationreturns the stored descriptor for an already-committed action and short-circuits beforeassertRetractableLabel, so a legitimate replay of a successful retract returns 200 (not re-checked). A 404 never commits, so it cannot be replayed as success. Correct. - Error handling.
NoActiveLabelErroris added to the top-levelinstanceofchain inhandleConsoleMutation; its{ error: { code, message } }envelope with status 404 matches the siblingLabelMutationError/DeadLetterResolvedErrorshapes. Static message; the code (NO_ACTIVE_LABEL) leaks nothing an admin can't already see via the console read, and non-admins are 403'd first. - TOCTOU. The read and the commit are not atomic, but the only harmful direction (false reject blocking a legitimate undo) is bounded by reading the same binding/state the console shows; the opposite direction (label negates/expires between read and commit) merely signs a negation that becomes the new winner — pre-existing behavior, no regression. Concurrent double-retract behaves as before this PR.
- Tests. New suite covers the active happy path for all four label/subject combinations (release+takedown, package+takedown, publisher+takedown, publisher+publisher-compromised), the no-active-label 404 on both retract endpoints with
globalCountsbefore/after zero-side-effect assertions, the already-retracted double-retract → 404, and the 403-before-guard / 400-before-guard ordering. The previously-shared-DB-dependent "emits a high-severity event for a retract" test was correctly rewritten to issue its own takedown first (it would otherwise 404 under the new guard). Helpers (countRows,bodyError,globalCounts) are sound. - Conventions. Raw D1 with bound
?placeholders (no interpolation);apps/labelerisprivate: truev0.0.0 so changeset n/a is correct; no admin-UI strings so i18n n/a; no content-table/locale concerns apply. The trailingdeadLetterRowreflow is an oxfmt pass on a file this PR already touches, not a drive-by on an unrelated file.
Conclusion
Clean, well-scoped, well-tested hardening with no logic bugs, regressions, security/authorization gaps, or convention violations found. The claim that cid: "" always finds the URI-wide emergency-label winner holds against the fixture and the getActiveLabelState implementation. Approving.
3792edf
into
feat/plugin-registry-labelling-service
What does this PR do?
A small ratified hardening (2026-07-14) to the W9.6 emergency-action retract endpoints. Previously, retracting a
!takedownorpublisher-compromisedlabel that wasn't in effect succeeded anyway — it signed a no-opneg:truelabel and emitted a high-severity operational event, returning 200 for a takedown that was never live. Now the retract endpoints pre-check that the target positive label is currently active and reject with 404NO_ACTIVE_LABELif it isn't — so no no-op negation is signed and no spurious alert fires.assertRetractableLabelreads the same stream winner official clients see (getActiveLabelState) and rejects unless the winner for the targetvalexists and isactive(non-negated, unexpired). The read passescid: ""— every emergency label iscidRule: forbidden(URI-wide / DID, stored withcidNULL), so the URI-wide winner is always found regardless of subject kind.guardMutation's role gate (a reviewer still gets 403, never a 404 leaking label state) and after the typed-ceremony validation (a wrong confirmation still gets 400), but beforecreateSigner/prepareManualLabelIssuance/commitMutation. An absent, already-negated, or expired label commits nooperator_actions,issued_labels,operational_events, ornotification_outboxrow.Handler-only change (
console-mutation-api.ts+ its test); the console isn't touched — a retract on a stale view surfaces a clean 404. Nothing frozen was touched.This resolves one of four post-review decisions on the merged W9.6 (the other three — audit
actionshape, pause alerting, DLQ concurrent-loser accuracy — were ratified as leave-as-is; all four are recorded in the plan).Adversarially reviewed by an independent Opus pass focused on the one dangerous failure mode — a false-positive rejection that would block a legitimate takedown undo. It proved, per subject kind, that
cid: ""finds the active winner for release/package/publisher takedown and publisher-compromised (all storecidNULL), that the guard fires on both retract endpoints and can't be bypassed (replay only short-circuits an already-guarded action), and that ordering/zero-side-effects/no-info-leak all hold: no blockers. It closed the real coverage gap — the initial happy-path test only covered release/takedown, so it added the package/takedown, publisher/takedown, and publisher-compromised/DID issue→retract→200 round-trips, all folded in.Stacked on the integration branch (all W9.6 merged). Targets
feat/plugin-registry-labelling-service. Related to #1909 and RFC #694.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.i18n n/a — no admin UI; the labeler console isn't localized (decision 2026-07-13), and this PR touches no console strings. Changeset n/a —
apps/labeleris a private, unpublished Worker app. Bug fix on unreleased W9.6 code, so no Discussion needed beyond the existing RFC #694.AI-generated code disclosure
Screenshots / test output
pnpm --filter @emdash-cms/labeler test: worker 546 pass (28 files; the emergency-retract-guard suite covers the active-label happy path for all four label/subject combinations, the no-active-label 404 with four-count zero-side-effect assertions on both retract endpoints, the already-retracted double-retract edge, and the 403-before-guard / 400-before-guard ordering), console 35 passapps/labelerhttps://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
Try this PR
Open a fresh playground →
A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.
Tracks
feat/labeler-retract-guard. Updated automatically when the playground redeploys.