Skip to content

Commit 63f4acb

Browse files
steipetePeter Steinberger
andauthored
fix(exec): leave safe builtins unrewritten in enforced mode (#119351)
Enforced-mode command rendering resolved every executable to an absolute path, including POSIX shell builtins (cd, :, true, false, pwd, test). Builtins are executed by the shell itself, not via a filesystem binary, so rewriting cd -> /usr/bin/cd is semantically wrong and adds no PATH-shadowing protection (the whole point of enforced-mode resolution for real external executables). shouldRewriteCandidate now returns satisfiedBy !== "safeBuiltins" in enforced mode, leaving real external executables pinned to their resolved absolute path. Adds a regression test locking that enforced mode renders cd . as-is. Co-authored-by: Peter Steinberger <[email protected]>
1 parent 9bfe292 commit 63f4acb

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎src/infra/exec-authorization-render.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ describe("exec authorization renderer", () => {
157157
expect(command).toMatch(/^\/.+\/head -c 16$/);
158158
});
159159

160+
it("leaves POSIX safe builtins unrewritten in enforced mode", async () => {
161+
const plan = await planShellAuthorization({
162+
command: "cd .",
163+
env: POSIX_ENV,
164+
});
165+
166+
const command = renderOk(
167+
buildAuthorizedShellCommandFromPlan({
168+
plan,
169+
mode: "enforced",
170+
segmentSatisfiedBy: ["safeBuiltins"],
171+
}),
172+
);
173+
174+
// Builtins run in the shell, not via a filesystem executable, so enforced
175+
// mode must not rewrite `cd` to a resolved path like /usr/bin/cd.
176+
expect(command).toBe("cd .");
177+
});
178+
160179
it("rewrites quoted POSIX executable source spans", async () => {
161180
const plan = await planShellAuthorization({
162181
command: '"head" -c 16',

‎src/infra/exec-authorization-render.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ function shouldRewriteCandidate(params: {
130130
satisfiedBy: ExecSegmentSatisfiedBy | undefined;
131131
}): boolean {
132132
if (params.mode === "enforced") {
133-
return true;
133+
// Safe builtins (cd, :, true, false, pwd, test) are handled by the shell itself, not by an
134+
// external executable. Rewriting them to a resolved path (e.g. /usr/bin/cd) is semantically
135+
// wrong and does not strengthen PATH-shadowing protection, so enforced mode leaves them as-is.
136+
return params.satisfiedBy !== "safeBuiltins";
134137
}
135138
return params.satisfiedBy === "safeBins" || params.satisfiedBy === "inlineChain";
136139
}

0 commit comments

Comments
 (0)