Skip to content
Merged
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
3 changes: 2 additions & 1 deletion extensions/git-read/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function isSafeRevision(revision: string): boolean {
const REPO_PATH_PATTERN = /^[^:/\\?#*[\]'"\s][^:/\\?#*[\]'"\s]*$/;

export function isSafeRepoPath(value: string): boolean {
if (value.length === 0 || value.length > 512) return false;
if (value.length === 0 || value.length > 512 || value.includes("\0"))
return false;
const segments = value.split("/");
for (const segment of segments) {
if (segment === "" || segment === "." || segment === "..") return false;
Expand Down
11 changes: 11 additions & 0 deletions tests/extensions/git-read/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ test("buildLogArgs clamps the limit and validates inputs", () => {
assert.throws(() => buildLogArgs({ revision: "-n5" }), InvalidRevisionError);
assert.throws(() => buildLogArgs({ file: "a/../b" }), InvalidPathError);
});

test("git argv builders reject NUL bytes in repository paths", () => {
const path = "src\0secret.ts";

assert.throws(
() => buildShowArgs({ revision: "HEAD", path }),
InvalidPathError,
);
assert.throws(() => buildDiffArgs({ path }), InvalidPathError);
assert.throws(() => buildLogArgs({ file: path }), InvalidPathError);
});
Loading