Skip to content

Commit 8f8cc0f

Browse files
committed
chore: fix cross-platform path check in classifyWriteEdit
Remove POSIX-only startsWith('/') guard so absolute Windows paths (e.g. C:\Users\...) are no longer auto-allowed outside the project root. Now relies solely on resolvedPath.startsWith(process.cwd()) and uses path.sep for node_modules detection, making the check portable.
1 parent 9f940c8 commit 8f8cc0f

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

plugins/gatekeeper/dist/pre-tool-use.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function classifyWriteEdit(filePath) {
218218
}
219219
}
220220
const resolvedPath = path.resolve(filePath);
221-
if (!resolvedPath.startsWith("/") || resolvedPath.startsWith(process.cwd()) || resolvedPath.includes("/node_modules/")) {
221+
if (resolvedPath.startsWith(process.cwd()) || resolvedPath.includes(`${path.sep}node_modules${path.sep}`)) {
222222
return { decision: "allow", reason: "Safe project file write" };
223223
}
224224
return null;

plugins/gatekeeper/src/pre-tool-use.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ export function classifyWriteEdit(filePath: string): { decision: Decision, reaso
151151
}
152152
}
153153

154-
// Project-relative paths are generally safe; resolve to absolute path first to prevent path traversal
154+
// Resolve to absolute path first to prevent path traversal; allow only within project root
155155
const resolvedPath = path.resolve(filePath)
156-
if (!resolvedPath.startsWith('/') || resolvedPath.startsWith(process.cwd()) || resolvedPath.includes('/node_modules/')) {
156+
if (resolvedPath.startsWith(process.cwd()) || resolvedPath.includes(`${path.sep}node_modules${path.sep}`)) {
157157
return { decision: 'allow', reason: 'Safe project file write' }
158158
}
159159

0 commit comments

Comments
 (0)