Skip to content

Commit 8df455c

Browse files
authored
fix(acp-registry): ACP Registry installs only change the mode of a contained command (pingdotgg#34531)
Co-authored-by: maria-rcks <[email protected]>
1 parent 9c7f6eb commit 8df455c

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

‎packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,72 @@ describe("AcpRegistrySupport", () => {
839839
);
840840
});
841841

842+
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
843+
"leaves the mode of a file outside the install root when the command links to it",
844+
() => {
845+
const downloadUrl = "https://registry.test/agent.tar.gz";
846+
const agent = makeAgent({
847+
binary: { "linux-x86_64": { archive: downloadUrl, cmd: "./agent" } },
848+
});
849+
return Effect.gen(function* () {
850+
const fileSystem = yield* FileSystem.FileSystem;
851+
const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
852+
prefix: "t3-acp-outside-link-",
853+
});
854+
const outsideFile = `${cacheDir}/outside`;
855+
yield* fileSystem.writeFileString(outsideFile, "private\n");
856+
yield* fileSystem.chmod(outsideFile, 0o600);
857+
const source = `${cacheDir}/source`;
858+
yield* fileSystem.makeDirectory(source);
859+
yield* fileSystem.symlink(outsideFile, `${source}/agent`);
860+
const archivePath = `${cacheDir}/agent.tar.gz`;
861+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
862+
const tar = yield* spawner.spawn(
863+
ChildProcess.make("tar", ["-czf", archivePath, "-C", source, "agent"]),
864+
);
865+
expect(yield* tar.exitCode).toBe(0);
866+
const archive = yield* fileSystem.readFile(archivePath);
867+
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
868+
cacheDir,
869+
toolsDir: `${cacheDir}/tools`,
870+
registryUrl,
871+
}).pipe(
872+
Effect.provideService(
873+
HttpClient.HttpClient,
874+
HttpClient.make((request) =>
875+
Effect.succeed(
876+
HttpClientResponse.fromWeb(
877+
request,
878+
request.url === registryUrl
879+
? new Response(makeRegistry(agent))
880+
: new Response(archive),
881+
),
882+
),
883+
),
884+
),
885+
);
886+
887+
const error = yield* resolver.prepare({ agentId: agent.id }).pipe(Effect.flip);
888+
889+
expect(error.reason).toBe("archive_invalid");
890+
expect((yield* fileSystem.stat(outsideFile)).mode & 0o777).toBe(0o600);
891+
}).pipe(
892+
Effect.scoped,
893+
Effect.provide(
894+
Layer.mergeAll(
895+
NodeServices.layer,
896+
NodeCrypto.layer,
897+
TestProviderHost.layer().pipe(
898+
Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
899+
),
900+
),
901+
),
902+
Effect.provideService(HostProcess.Platform, "linux"),
903+
Effect.provideService(HostProcess.Architecture, "x64"),
904+
);
905+
},
906+
);
907+
842908
it.effect("searches compatible agents with deterministic ranking and bounded metadata", () => {
843909
const exact = {
844910
...makeAgent({ npx: { package: "@example/[email protected]" } }),

‎packages/provider-acp-registry/src/server/AcpRegistrySupport.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
13561356
const assertExecutableInRoot = Effect.fn("AcpRegistryCatalog.assertExecutableInRoot")(function* (
13571357
root: string,
13581358
executablePath: string,
1359+
options?: { readonly makeExecutable?: boolean },
13591360
) {
13601361
const rootRealPath = yield* fileSystem.realPath(root);
13611362
const executableRealPath = yield* fileSystem.realPath(executablePath);
@@ -1366,6 +1367,10 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
13661367
detail: "ACP Registry archive command resolves outside its installation directory.",
13671368
});
13681369
}
1370+
// chmod follows symlinks, so only change the mode once the real path is known to be inside.
1371+
if (options?.makeExecutable && platform !== "win32") {
1372+
yield* fileSystem.chmod(executableRealPath, 0o755);
1373+
}
13691374
const info = yield* fileSystem.stat(executableRealPath);
13701375
const hasExecutableMode = platform === "win32" || (info.mode & 0o111) !== 0;
13711376
if (info.type !== "File" || !hasExecutableMode) {
@@ -1595,8 +1600,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
15951600
detail: `ACP Registry archive for ${agent.id} did not contain '${target.cmd}'.`,
15961601
});
15971602
}
1598-
if (platform !== "win32") yield* fileSystem.chmod(stagedExecutable, 0o755);
1599-
yield* assertExecutableInRoot(extractionRoot, stagedExecutable);
1603+
yield* assertExecutableInRoot(extractionRoot, stagedExecutable, { makeExecutable: true });
16001604
yield* fileSystem.remove(installRoot, { recursive: true, force: true });
16011605
yield* fileSystem.rename(extractionRoot, installRoot);
16021606
return yield* assertExecutableInRoot(installRoot, executablePath);

0 commit comments

Comments
 (0)