Skip to content

feat(labeler): acquire consumer, SSRF egress, image stage, and gate lift (slice B) - #2091

Merged
ascorbic merged 2 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-acquire-consumer
Jul 17, 2026
Merged

ascorbic merged 2 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-acquire-consumer

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

The keystone slice: it makes the labeler perform a real production assessment and lifts the deploy gate. Targets the feat/plugin-registry-labelling-service integration branch (RFC #694, umbrella #1909), stacked on the stage-wiring slice (#2090).

Until now the assessment orchestrator ran deploy-gated stub stages — a production build refused to start, because with stubs every subject would finalize passed and sign a real assessment-passed label over unscanned content. This slice supplies the missing bundle-production half so all four stages are real, then removes the gate.

  • artifact-egress.ts — the SSRF-hardened { fetch, resolveHostname } for artifact acquisition. resolveHostname is the ratified cloudflareDohResolver (DoH, fails closed); fetch is a bare globalThis.fetch pass-through so fetchVerifiedResource keeps full control of redirects, budgets, and per-hop re-resolution. No recursion — the DoH lookup uses its own fetch to a fixed trusted host.
  • release-resolution.ts — resolveTarget reads the assessment's pinned release from the aggregator ReleaseView (getLatestRelease, falling back to a listReleases scan for the pinned CID) and extracts the signed declared URL + checksum, setting the pinned coordinates so acquisition's crossCheckCoordinates raises a permanent integrity finding on any drift. Aggregator-miss classifies transient (retry), never a false block. Threads the package description (best-effort) into the code stage so misleading-metadata / privacy-risk detection isn't fed an empty purpose.
  • image-metadata.ts — deterministic bundle-bytes → ImageAnalysisImage: magic-byte MIME (never extension-trust), header dimensions with bounds-checks, SHA-256 + base64 with the size cap enforced before base64 materialization; a malformed image is skipped (→ partial coverage), never thrown.
  • createImageAiStage + real image coverage; buildStages assembles the four real stages over injected deps (pure — no env, no network — so tests drive it with fakes); executeAssessmentInstance builds the per-run holder/coverage, asserts required bindings, and threads them. The import.meta.env.PROD gate is removed.
  • Orchestrator hardening: a later stage's transient exhaustion no longer discards a block an earlier stage already found — the run finalizes blocked on partial coverage (a confirmed block is monotonic; no unrun stage can lift it), while clean/warn-incomplete still finalizes error. This closes an indefinite block-evasion (a plugin pairing block-worthy code with a model-breaking image).
  • registry-verification SSRF guard: rejects IPv4-compatible (::a.b.c.d) and NAT64 (64:ff9b::a.b.c.d) IPv6 encodings of private/metadata addresses it previously missed (strictly more restrictive).
  • Exposes emdash/security/ssrf for the DoH resolver.

PROD-safety argument for the gate lift

A run reaches passed only after the acquire stage returned no finding, and the acquire stage returns no finding iff it published a checksum-verified, structurally-valid bundle to the holder: a permanent failure returns a blocking finding, a transient failure (incl. aggregator lag) throws, and a malformed state aborts the run running. There is no path where the holder is empty/unverified yet the run finalizes passed, and the code/image stages report clean only after really analyzing the real bundle. assertRequiredBindings fails loudly on a missing binding before any stage runs. Verified by an adversarial review pass (gate-lift core invariant and SSRF main path both confirmed HOLD) and by tests.

Follows #2090. Part of #1909. Related to #694.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (all three labeler projects)
  • pnpm lint passes (no new diagnostics)
  • pnpm test passes (new units for egress, release-resolution, image-metadata; orchestrator block-preserve + workflow end-to-end cases; full labeler suite 1003, registry-verification 96+36)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable) — n/a: server-only.
  • I have added a changeset (if this PR changes a published package) — yes: two — emdash (patch, the new security/ssrf export) and @emdash-cms/registry-verification (patch, the SSRF-guard hardening). The labeler app itself is private.
  • New features link to an approved Discussion — the umbrella Plugin registry labelling service #1909 tracks RFC RFC: Decentralized Plugin Registry #694; this is one slice under it.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.8 (implementation + adversarial review), orchestrated by Claude Fable 5

Screenshots / test output

labeler suite:            1003 passed
registry-verification:    96 + 36 passed
typecheck (3 projects):   clean

Adversary-confirmed invariants: the gate-lift admits no false passed, and the SSRF main path reaches no private/internal address (with the two IPv6-encoding gaps now closed). Note: actual production enforcement additionally awaits the calibration sweep (the production prompt + capabilities-only + real-description inputs must be re-validated; model_id/prompt_hash provenance is provisional until then) and the operator-owned Email Sending onboarding — both tracked separately.


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-acquire-consumer. Updated automatically when the playground redeploys.

…ift (slice B)

Makes the labeler perform a real production assessment. The acquire stage
now resolves an assessment's pinned release from the aggregator, fetches its
declared artifact under an SSRF-hardened egress, and publishes the verified
bundle; the code, image, and history stages run over it; and the production
deploy gate lifts — a `passed` outcome now means a genuine clean scan.

- artifact-egress.ts: the production {fetch, resolveHostname} for acquisition
  — resolveHostname is the DoH resolver (fails closed), fetch is a bare
  globalThis.fetch pass-through so fetchVerifiedResource keeps full control of
  redirects/budgets. No recursion: the DoH call uses its own fetch to a fixed
  host.
- release-resolution.ts: resolveTarget reads the pinned release's declared URL
  + checksum from the aggregator ReleaseView (getLatestRelease, falling back to
  a listReleases scan for the pinned cid), sets the pinned coordinates so
  acquisition's crossCheckCoordinates raises a permanent integrity finding on
  drift; aggregator-miss classifies transient. Threads the package
  description (best-effort) into the code stage.
- image-metadata.ts: deterministic bundle-bytes -> ImageAnalysisImage —
  magic-byte mime, header dimensions, sha256 + base64, caps enforced before
  base64 materialization; malformed images are skipped, never thrown.
- createImageAiStage + real image coverage; buildStages assembles the four
  real stages over injected deps; executeAssessmentInstance builds the per-run
  holder/coverage and asserts required bindings; the import.meta.env.PROD gate
  is removed (safe only because every stage is now real — acquire returns no
  finding iff it published a verified bundle).
- orchestrator: a later stage's transient exhaustion no longer discards a
  block an earlier stage already found (finalize blocked on partial coverage;
  clean/warn-incomplete still -> error), closing an indefinite block-evasion.
- registry-verification: the verified-fetch SSRF guard rejects IPv4-compatible
  and NAT64 IPv6 encodings of private/metadata addresses.
- Exposes emdash/security/ssrf for the DoH resolver.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@changeset-bot

changeset-bot Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 34e0079

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
emdash Patch
@emdash-cms/registry-verification Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/labeler Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 34e0079 Jul 17 2026, 01:01 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do 34e0079 Jul 17 2026, 01:01 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 34e0079 Jul 17 2026, 01:01 PM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 2,046 lines across 22 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet cla: signed labels Jul 17, 2026

@emdashbot emdashbot 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.

This is the right slice for the umbrella (#1909 / RFC #694): it finally wires a real acquire → code → image → history pipeline and removes the production stub gate. The approach fits EmDash’s architecture (pure adapters, injected deps, per-run shared holder/coverage, aggregator service binding) and the safety argument is coherent: passed can only follow a verified bundle because the acquire stage either publishes to the holder or throws/returns a blocking finding.

I checked the diff, the full source of the new and changed modules, the registry-verification SSRF guard, the orchestrator finalization path, and the image format parsers. The code is mostly clean and well-tested. I found one real bug and one stale comment:

  1. Unbounded release description can abort a run and suppress a block/warn outcome. release-resolution.ts threads the package-profile description into the code and image model prompts as best-effort context, but extractProfileDescription returns the raw string with no length cap. Both AI adapters throw a non-retryable TypeError if the fixed prompt overhead exceeds MAX_MODEL_INPUT_CHARS (code-ai-adapter.ts ~L307, image-ai-adapter.ts analogous). The stage adapters only convert ModelTransientError to StageTransientError, so a publisher-controlled oversized description propagates out of createCodeAiStage, aborts runAssessment, and leaves the assessment in running indefinitely — a deterministic way to prevent a block/warn label from finalizing.

  2. Stale module comment in assessment-orchestrator.ts. The top block still warns that the orchestrator runs stub stages and that this is a hard deploy gate; the gate has been lifted in assessment-workflow.ts, so the comment is now misleading.

Both are fixable in small follow-on edits.


Findings

  • [needs fixing] apps/labeler/src/release-resolution.ts:163-165

    extractProfileDescription returns the raw profile.description with no length cap. That string is injected into the code and image model prompts as metadata.description (assessment-stages.ts L120 and L181). If the publisher profile contains a very long description, the fixed prompt overhead in analyzeCode/analyzeImages can exceed MAX_MODEL_INPUT_CHARS, causing a TypeError that is not translated into StageTransientError. The orchestrator then aborts the run and leaves the row in running, so a confirmed block later in the pipeline can never finalize. Since the description is explicitly best-effort analysis context, cap it at ingestion time so it can never blow the model budget.

    const MAX_RELEASE_DESCRIPTION_CHARS = 4096;
    
    function extractProfileDescription(profile: unknown): string | undefined {
    	if (!isRecord(profile)) return undefined;
    	if (typeof profile.description !== "string") return undefined;
    	if (profile.description.length <= MAX_RELEASE_DESCRIPTION_CHARS) return profile.description;
    	return `${profile.description.slice(0, MAX_RELEASE_DESCRIPTION_CHARS)}…`;
    }
    

    Add a test for the truncation behavior.

  • [suggestion] apps/labeler/src/assessment-orchestrator.ts:8-17

    The module-level comment still states that the Workflow runs stub stages and that this is a hard deploy gate. That gate was lifted in this PR (assessment-workflow.ts now assembles the four real stages), so the comment is stale and likely to confuse the next reader. Update it to reflect that the real adapters are wired in assessment-workflow.ts, while stubStages remains only for tests that need an empty pass.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Jul 17, 2026
A publisher-controlled package description was threaded into the AI prompts
uncapped; a long enough one pushes the fixed prompt overhead past
MAX_MODEL_INPUT_CHARS, and the adapters throw a plain TypeError (not the
ModelTransientError the stage converts). That aborts the run and leaves it
stuck 'running', so the subject's block/warn label never finalizes — a
publisher could evade a block by padding their description. Cap the
description at ingestion (4096 chars, truncated) so it can never blow the
budget; the adapters' behavior is unchanged.

Also updates the stale orchestrator module comment that still described the
lifted stub-stage deploy gate.

Addresses the emdashbot review on #2091.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 17, 2026
@ascorbic

Copy link
Copy Markdown
Member Author

Both findings addressed (commit 34e0079).

Finding 1 (block-suppression via description) — fixed. extractProfileDescription now caps the publisher description at MAX_RELEASE_DESCRIPTION_CHARS = 4096 at ingestion (truncated with an ellipsis to exactly 4096 chars), so it can never push the fixed prompt overhead past MAX_MODEL_INPUT_CHARS — no non-transient TypeError, no stalled running row, the block/warn label finalizes. The adapters' budget/throw behavior is untouched (kept calibration-stable); the cap is at ingestion only. A release-resolution test asserts an over-cap description is truncated to the cap. Good catch — this is the same block-suppression class as the image-transient finding the adversarial pass caught, via a distinct publisher-controlled vector.

Finding 2 (stale comment) — fixed. The assessment-orchestrator.ts module docblock no longer describes the lifted stub-stage deploy gate; it now states the real adapters are assembled in assessment-workflow.ts and that stubStages is test-only.

Full labeler suite 1004 green, typecheck (3 projects) clean, lint/format clean.

~ 🤖 Claude Fable 5

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026

@emdashbot emdashbot 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.

This is the right slice for #1909 / RFC #694: it removes the production stub gate and wires a real acquire → code → image → history pipeline. The approach still fits EmDash’s architecture (pure adapters with injected deps, per-run shared holder/coverage, aggregator reads, DoH/verified-fetch SSRF egress) and the PROD-safety argument is coherent.

I re-read the diff, the full source of the new and changed modules, the registry-verification SSRF guard, the block-preservation path, the image-metadata parsers, and the added tests. Both findings from the previous review are resolved:

  • release-resolution.ts now caps extractProfileDescription at MAX_RELEASE_DESCRIPTION_CHARS (with a Unicode ellipsis), so a publisher-supplied oversized description can no longer blow the model prompt budget and abort the run; a unit test asserts the truncation behavior.
  • assessment-orchestrator.ts module-level comment has been updated and no longer claims the orchestrator runs stub stages by default.

I also checked the new/changed surface for regressions:

  • buildStages assembles the four real stages from injected deps; assertRequiredBindings fails loudly on missing AI/AGGREGATOR/DB before any stage runs.
  • executeAssessmentInstance short-circuits terminal rows idempotently.
  • The orchestrator finalizes blocked when a later stage transient-exhausts after an earlier stage found a block, while any non-block incomplete outcome finalizes error (tests cover both paths).
  • The registry-verification SSRF guard now rejects deprecated IPv4-compatible (::a.b.c.d) and NAT64 (64:ff9b::a.b.c.d) encodings of private/metadata addresses, with tests.
  • The emdash/security/ssrf subpath export is wired through packages/core/package.json and tsdown.config.ts.

No remaining issues. The gate lift looks clean.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Jul 17, 2026
@ascorbic
ascorbic merged commit 0bb7e7c into feat/plugin-registry-labelling-service Jul 17, 2026
11 checks passed
@ascorbic
ascorbic deleted the feat/labeler-acquire-consumer branch July 17, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant