Skip to content

Commit 267e642

Browse files
committed
fix(server): reject NUL bytes in selected commit paths
1 parent e1bd5c5 commit 267e642

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,6 +5073,22 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
50735073
for (const file of selected) yield* writeTextFile(cwd, file, "literal\n");
50745074
yield* writeTextFile(cwd, "selected1.txt", "pattern match\n");
50755075

5076+
yield* git(cwd, ["add", "selected1.txt"]);
5077+
const stagedBefore = yield* git(cwd, ["diff", "--cached"]);
5078+
const headBefore = yield* git(cwd, ["rev-parse", "HEAD"]);
5079+
const invalidSelection = ["selected[1].txt\0:(top,glob)**"];
5080+
const prepared = yield* driver
5081+
.prepareCommitContext(cwd, invalidSelection)
5082+
.pipe(Effect.result);
5083+
const committed = yield* driver
5084+
.commit(cwd, "Invalid selection", "", { stage: { filePaths: invalidSelection } })
5085+
.pipe(Effect.result);
5086+
assert.isTrue(Result.isFailure(prepared));
5087+
assert.isTrue(Result.isFailure(committed));
5088+
assert.equal(yield* git(cwd, ["diff", "--cached"]), stagedBefore);
5089+
assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), headBefore);
5090+
yield* git(cwd, ["reset"]);
5091+
50765092
const context = yield* driver.prepareCommitContext(cwd, selected);
50775093

50785094
assert.include(context?.stagedSummary ?? "", "selected[1].txt");

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
23962396
filePaths?: readonly string[],
23972397
env?: NodeJS.ProcessEnv,
23982398
) {
2399+
if (filePaths?.some((file) => file.includes("\0"))) {
2400+
return yield* new GitCommandError({
2401+
operation: "GitVcsDriver.commit",
2402+
command: "git add",
2403+
cwd,
2404+
detail: "Selected file paths must not contain NUL bytes.",
2405+
});
2406+
}
23992407
const config = env
24002408
? ["-c", "core.splitIndex=false", "-c", "splitIndex.sharedIndexExpire=never"]
24012409
: [];

0 commit comments

Comments
 (0)