|
1 | 1 | // Windows path handling, characterized on any host (#4854). The `path` module |
2 | 2 | // is replaced by `path.win32` and `process.platform` reads "win32", so the |
3 | 3 | // Windows-only branches of path-utils.ts and path-validation.ts run here: |
4 | | -// drive roots, bare drive letters, backslash conversion and UNC shares. #3527 |
5 | | -// (a UNC share as the allowed root refuses its own subdirectories) is pinned |
6 | | -// as it stands. |
| 4 | +// drive roots, bare drive letters, backslash conversion and UNC shares. |
7 | 5 |
|
8 | 6 | import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; |
9 | 7 |
|
@@ -85,14 +83,61 @@ describe("isPathWithinAllowedDirectories on win32", () => { |
85 | 83 | ).toBe(true); |
86 | 84 | }); |
87 | 85 |
|
88 | | - // KNOWN BUG #3527: pins current (wrong) behavior; the fix changes this assertion. |
89 | | - // #3527: path.resolve keeps a UNC root's trailing backslash, and the prefix |
90 | | - // check appends another, so nothing below the share matches. |
91 | | - it("refuses a subdirectory of a UNC share allowed directory (#3527)", () => { |
| 86 | + // #3527: path.resolve keeps a UNC share root's trailing backslash, so the |
| 87 | + // prefix check must not append a second one. |
| 88 | + it("accepts a subdirectory of a UNC share allowed directory (#3527)", () => { |
92 | 89 | expect( |
93 | 90 | isPathWithinAllowedDirectories("\\\\server\\share\\sub", [ |
94 | 91 | "\\\\server\\share\\", |
95 | 92 | ]), |
| 93 | + ).toBe(true); |
| 94 | + }); |
| 95 | + |
| 96 | + it("accepts a deep path under a UNC share given without a trailing backslash", () => { |
| 97 | + expect( |
| 98 | + isPathWithinAllowedDirectories("\\\\server\\share\\a b\\.c\\f.txt", [ |
| 99 | + "\\\\server\\share", |
| 100 | + ]), |
| 101 | + ).toBe(true); |
| 102 | + }); |
| 103 | + |
| 104 | + it("refuses a sibling share whose name extends the allowed share's", () => { |
| 105 | + expect( |
| 106 | + isPathWithinAllowedDirectories("\\\\server\\share-evil\\x", [ |
| 107 | + "\\\\server\\share\\", |
| 108 | + ]), |
| 109 | + ).toBe(false); |
| 110 | + expect( |
| 111 | + isPathWithinAllowedDirectories("\\\\server\\share-evil", [ |
| 112 | + "\\\\server\\share", |
| 113 | + ]), |
| 114 | + ).toBe(false); |
| 115 | + }); |
| 116 | + |
| 117 | + it("refuses another share, and the same share on another server", () => { |
| 118 | + expect( |
| 119 | + isPathWithinAllowedDirectories("\\\\server\\other\\x", [ |
| 120 | + "\\\\server\\share\\", |
| 121 | + ]), |
| 122 | + ).toBe(false); |
| 123 | + expect( |
| 124 | + isPathWithinAllowedDirectories("\\\\server2\\share\\x", [ |
| 125 | + "\\\\server\\share\\", |
| 126 | + ]), |
| 127 | + ).toBe(false); |
| 128 | + }); |
| 129 | + |
| 130 | + it("keeps a .. that climbs past a UNC share root inside that share", () => { |
| 131 | + // Node clamps .. at the share root, so this resolves to \\server\share\other. |
| 132 | + expect( |
| 133 | + isPathWithinAllowedDirectories("\\\\server\\share\\..\\other\\x", [ |
| 134 | + "\\\\server\\share\\", |
| 135 | + ]), |
| 136 | + ).toBe(true); |
| 137 | + expect( |
| 138 | + isPathWithinAllowedDirectories("\\\\server\\share\\sub\\..\\..\\x", [ |
| 139 | + "\\\\server\\share\\sub", |
| 140 | + ]), |
96 | 141 | ).toBe(false); |
97 | 142 | }); |
98 | 143 | }); |
0 commit comments