Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: publish the digest verified from stored audio bytes

Richie McIlroyf3f2d7ad33e4
diff --git a/apps/media-server/audio-quality-benchmarks.md b/apps/media-server/audio-quality-benchmarks.md
index b0def2f39..73b5c642b 100644
--- a/apps/media-server/audio-quality-benchmarks.md
+++ b/apps/media-server/audio-quality-benchmarks.md
@@ -31,6 +31,15 @@ two one-byte identity reads. Media bytes travel directly to storage; the web cal
only handles metadata and signed URLs. Output verification has its own reserved
transfer budget, independent of the completed original job's download budget.
+Stored-byte verification happens in the authenticated media worker, before the
+publication callback. It hashes a complete conditional GET, compares SHA-256 with
+the locally validated derivative, and checks the strong ETag and size before and
+after that read. The callback carries the digest returned by this remote verifier.
+The web transaction pins the same verified identity with metadata checks instead
+of downloading the media again. Corrupted bytes are rejected even when the mocked
+storage preserves ETag and size. Storage must honor strong ETag/If-Match semantics;
+these checks do not treat an ETag as a cryptographic digest.
+
The original becomes playable before correction. Corrections run only with spare
capacity, use one FFmpeg decoder/filter thread, and occupy one audio slot per replica.
Clearing the two audio selection fields restores the retained original. Rolling back
diff --git a/apps/media-server/src/__tests__/lib/audio-levels.integration.test.ts b/apps/media-server/src/__tests__/lib/audio-levels.integration.test.ts
index 475f831c0..bd88592b2 100644
--- a/apps/media-server/src/__tests__/lib/audio-levels.integration.test.ts
+++ b/apps/media-server/src/__tests__/lib/audio-levels.integration.test.ts
@@ -146,7 +146,8 @@ function storage(
);
}
publications++;
- expect(output).toBeDefined();
+ if (!output) throw new Error("Output not uploaded");
+ expect(body.outputSha256).toBe(hash(new Uint8Array(output)));
expect(body.action).toBe("publish");
return Response.json({
status: options.rejectPublication ? "unchanged" : "published",
@@ -160,6 +161,7 @@ function storage(
return new Response(null, { headers: { ETag: '"output"' } });
}
if (!output) throw new Error("Output not uploaded");
+ expect(new Headers(init?.headers).get("If-Match")).toBe('"output"');
if (new Headers(init?.headers).get("range") === "bytes=0-0") {
downloadedBytes++;
return new Response(output.slice(0, 1), {
diff --git a/apps/media-server/src/lib/audio-levels.ts b/apps/media-server/src/lib/audio-levels.ts
index 90f4f2a77..90b639adf 100644
--- a/apps/media-server/src/lib/audio-levels.ts
+++ b/apps/media-server/src/lib/audio-levels.ts
@@ -136,7 +136,7 @@ export async function enhanceLocalRecording(input: {
);
const result = {
sourceSha256: candidate.sourceSha256,
- outputSha256: candidate.outputSha256,
+ outputSha256: verified.remoteSha256,
outputIdentity: verified.objectIdentity,
outputSize,
inputLufs: candidate.input.lufs,
diff --git a/apps/web/lib/audio-level-publication.ts b/apps/web/lib/audio-level-publication.ts
index eb6b8aa0c..0cdce755e 100644
--- a/apps/web/lib/audio-level-publication.ts
+++ b/apps/web/lib/audio-level-publication.ts
@@ -246,6 +246,7 @@ export async function handleAudioLevelPublication(payload: unknown) {
.headObject(context.outputKey)
.pipe(Effect.timeout("10 seconds"), runWorkflowPromise),
]);
+ // The authenticated worker hashes stored bytes with If-Match; retain that verified identity without another download.
if (
source.ETag !== context.sourceIdentity ||
source.ContentLength !== context.sourceSize ||