Repository navigation
feat(labeler): acquire consumer, SSRF egress, image stage, and gate lift (slice B) - #2091
Conversation
…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 detectedLatest commit: 34e0079 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 34e0079 | Jul 17 2026, 01:01 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 34e0079 | Jul 17 2026, 01:01 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 34e0079 | Jul 17 2026, 01:01 PM |
Scope checkThis 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. |
There was a problem hiding this comment.
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:
-
Unbounded release description can abort a run and suppress a block/warn outcome.
release-resolution.tsthreads the package-profile description into the code and image model prompts as best-effort context, butextractProfileDescriptionreturns the raw string with no length cap. Both AI adapters throw a non-retryableTypeErrorif the fixed prompt overhead exceedsMAX_MODEL_INPUT_CHARS(code-ai-adapter.ts~L307,image-ai-adapter.tsanalogous). The stage adapters only convertModelTransientErrortoStageTransientError, so a publisher-controlled oversized description propagates out ofcreateCodeAiStage, abortsrunAssessment, and leaves the assessment inrunningindefinitely — a deterministic way to prevent a block/warn label from finalizing. -
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 inassessment-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-165extractProfileDescriptionreturns the rawprofile.descriptionwith no length cap. That string is injected into the code and image model prompts asmetadata.description(assessment-stages.tsL120 and L181). If the publisher profile contains a very long description, the fixed prompt overhead inanalyzeCode/analyzeImagescan exceedMAX_MODEL_INPUT_CHARS, causing aTypeErrorthat is not translated intoStageTransientError. The orchestrator then aborts the run and leaves the row inrunning, 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-17The 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.tsnow 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 inassessment-workflow.ts, whilestubStagesremains only for tests that need an empty pass.
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]>
|
Both findings addressed (commit 34e0079). Finding 1 (block-suppression via description) — fixed. Finding 2 (stale comment) — fixed. The Full labeler suite 1004 green, typecheck (3 projects) clean, lint/format clean. ~ 🤖 Claude Fable 5 |
There was a problem hiding this comment.
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.tsnow capsextractProfileDescriptionatMAX_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.tsmodule-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:
buildStagesassembles the four real stages from injected deps;assertRequiredBindingsfails loudly on missingAI/AGGREGATOR/DBbefore any stage runs.executeAssessmentInstanceshort-circuits terminal rows idempotently.- The orchestrator finalizes
blockedwhen a later stage transient-exhausts after an earlier stage found a block, while any non-block incomplete outcome finalizeserror(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/ssrfsubpath export is wired throughpackages/core/package.jsonandtsdown.config.ts.
No remaining issues. The gate lift looks clean.
0bb7e7c
into
feat/plugin-registry-labelling-service
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-serviceintegration 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
passedand sign a realassessment-passedlabel 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.resolveHostnameis the ratifiedcloudflareDohResolver(DoH, fails closed);fetchis a bareglobalThis.fetchpass-through sofetchVerifiedResourcekeeps 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—resolveTargetreads the assessment's pinned release from the aggregatorReleaseView(getLatestRelease, falling back to alistReleasesscan for the pinned CID) and extracts the signed declared URL + checksum, setting the pinned coordinates so acquisition'scrossCheckCoordinatesraises 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;buildStagesassembles the four real stages over injected deps (pure — noenv, no network — so tests drive it with fakes);executeAssessmentInstancebuilds the per-run holder/coverage, asserts required bindings, and threads them. Theimport.meta.env.PRODgate is removed.blockedon partial coverage (a confirmed block is monotonic; no unrun stage can lift it), while clean/warn-incomplete still finalizeserror. This closes an indefinite block-evasion (a plugin pairing block-worthy code with a model-breaking image).registry-verificationSSRF 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).emdash/security/ssrffor the DoH resolver.PROD-safety argument for the gate lift
A run reaches
passedonly 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 runrunning. There is no path where the holder is empty/unverified yet the run finalizespassed, and the code/image stages report clean only after really analyzing the real bundle.assertRequiredBindingsfails 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
Checklist
pnpm typecheckpasses (all three labeler projects)pnpm lintpasses (no new diagnostics)pnpm testpasses (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 formathas been runemdash(patch, the newsecurity/ssrfexport) and@emdash-cms/registry-verification(patch, the SSRF-guard hardening). The labeler app itself is private.AI-generated code disclosure
Screenshots / test output
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_hashprovenance 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.