Skip to content

Commit 48ad39f

Browse files
fix(file-transfer): expand Windows-style tilde globs
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
1 parent 5bb905c commit 48ad39f

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

extensions/file-transfer/src/shared/policy.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ describe("evaluateFilePolicy — denyPaths always wins", () => {
176176
expectResultFields(r, { ok: false, code: "POLICY_DENIED", askable: false });
177177
});
178178

179+
it("expands Windows-style home globs in denyPaths", () => {
180+
withConfig({
181+
n1: {
182+
allowReadPaths: ["~/Downloads/**"],
183+
denyPaths: ["~\\Downloads\\**\\*.pem"],
184+
},
185+
});
186+
const r = evaluateFilePolicy({
187+
nodeId: "n1",
188+
kind: "read",
189+
path: path.join(os.homedir(), "Downloads", "key.pem"),
190+
});
191+
expectResultFields(r, { ok: false, code: "POLICY_DENIED", askable: false });
192+
});
193+
179194
it("preserves minimatch brace semantics in denyPaths", () => {
180195
withConfig({
181196
n1: {
@@ -284,6 +299,20 @@ describe("evaluateFilePolicy — allow matching", () => {
284299
);
285300
});
286301

302+
it("expands Windows-style home globs before matching", () => {
303+
withConfig({
304+
n1: { allowReadPaths: ["~\\Downloads\\**"] },
305+
});
306+
expectResultFields(
307+
evaluateFilePolicy({
308+
nodeId: "n1",
309+
kind: "read",
310+
path: path.join(os.homedir(), "Downloads", "shot.png"),
311+
}),
312+
{ ok: true },
313+
);
314+
});
315+
287316
it("matches Windows node paths without gateway-local path semantics", () => {
288317
withConfig({
289318
n1: { allowReadPaths: ["C:/Users/me/**"] },

extensions/file-transfer/src/shared/policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function readFilePolicyConfig(pluginConfig?: Record<string, unknown>): FilePolic
127127
}
128128

129129
function expandTilde(p: string): string {
130-
if (p.startsWith("~/") || p === "~") {
130+
if (p.startsWith("~/") || p.startsWith("~\\") || p === "~") {
131131
return path.join(os.homedir(), p.slice(p === "~" ? 1 : 2));
132132
}
133133
return p;

0 commit comments

Comments
 (0)