Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions sdk/typescript/src/trusted-executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export async function resolveTrustedExecutable(
const root = await realpath(protectedRoot).catch(() =>
resolve(protectedRoot),
);
const path = Object.entries(environment).find(
([name]) => name.toUpperCase() === "PATH",
)?.[1];
const path =
environment["PATH"] ??
Object.entries(environment).find(
([name]) => name.toUpperCase() === "PATH",
)?.[1];
const entries: string[] = [];
for (const entry of path?.split(delimiter) ?? []) {
if (entry.length === 0 || !isAbsolute(entry)) continue;
Expand Down
37 changes: 37 additions & 0 deletions sdk/typescript/tests-ts/trusted-executable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,43 @@ async function resolveWindowsExecutable(
}

describe("trusted executable resolution", () => {
test.skipIf(process.platform === "win32")(
"prefers the exact POSIX PATH over an earlier lowercase path variable",
async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
const decoy = join(root, "decoy");
const trusted = join(root, "trusted");
await Promise.all([mkdir(repository), mkdir(decoy), mkdir(trusted)]);
await Promise.all([
writeFile(join(decoy, "git"), "#!/bin/sh\nexit 1\n"),
writeFile(join(trusted, "git"), "#!/bin/sh\nexit 0\n"),
]);
await Promise.all([
chmod(join(decoy, "git"), 0o700),
chmod(join(trusted, "git"), 0o700),
]);

await expect(
resolveTrustedExecutable(
"git",
{
path: decoy,
PATH: trusted,
KEEP: "ok",
},
repository,
),
).resolves.toEqual({
executable: join(trusted, "git"),
environment: {
KEEP: "ok",
PATH: trusted,
},
});
},
);

test.skipIf(process.platform === "win32")(
"preserves the invocation name of a trusted symlinked executable",
async () => {
Expand Down