Skip to content

Commit ce147bf

Browse files
fix(server): hash ACP registry archives while streaming
Reading the downloaded archive back to verify its SHA-256 loaded up to 1 GiB into memory. Hash each chunk as it streams with @noble/hashes, since Effect's Crypto only digests a whole buffer. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 0197144 commit ce147bf

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎apps/server/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@effect/platform-node-shared": "catalog:",
3535
"@ff-labs/fff-node": "0.9.4",
3636
"@napi-rs/keyring": "^1.3.0",
37+
"@noble/hashes": "catalog:",
3738
"@opencode-ai/sdk": "^1.3.15",
3839
"@opencode/client": "2.0.23",
3940
"@opencode/protocol": "2.0.23",

‎apps/server/src/provider/acp/AcpRegistrySupport.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import * as Ref from "effect/Ref";
3737
import * as Schema from "effect/Schema";
3838
import * as Semaphore from "effect/Semaphore";
3939
import * as Stream from "effect/Stream";
40+
import { sha256 } from "@noble/hashes/sha2";
4041
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
4142
import { ChildProcess, ChildProcessSpawner } from "effect/process";
4243

@@ -1412,6 +1413,9 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14121413
),
14131414
}),
14141415
);
1416+
// Hash while streaming: archives can be up to MAX_ARCHIVE_BYTES, and
1417+
// Effect's Crypto only digests a whole buffer.
1418+
const hash = sha256.create();
14151419
let downloadedBytes = 0;
14161420
yield* response.stream.pipe(
14171421
Stream.tap((chunk) => {
@@ -1424,6 +1428,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14241428
);
14251429
}
14261430
downloadedBytes += chunk.byteLength;
1431+
hash.update(chunk);
14271432
return Effect.void;
14281433
}),
14291434
Stream.run(fileSystem.sink(archivePath)),
@@ -1448,17 +1453,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14481453
}),
14491454
);
14501455
if (target.sha256 !== undefined) {
1451-
const actual = yield* fileSystem.readFile(archivePath).pipe(
1452-
Effect.mapError(
1453-
(cause) =>
1454-
new AcpRegistryError({
1455-
reason: "download_failed",
1456-
detail: `Could not read ACP Registry agent ${agent.id} ${agent.version} download.`,
1457-
cause,
1458-
}),
1459-
),
1460-
Effect.flatMap(sha256Hex),
1461-
);
1456+
const actual = Hex.encode(hash.digest());
14621457
if (actual !== target.sha256.toLowerCase()) {
14631458
return yield* new AcpRegistryError({
14641459
reason: "checksum_mismatch",

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)