|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { normalizeRouteRules } from "../../src/config/resolvers/route-rules.ts"; |
| 3 | +import { isPathInScope } from "../../src/runtime/internal/route-rules.ts"; |
3 | 4 |
|
4 | 5 | describe("normalizeRouteRules - swr", () => { |
5 | 6 | it("swr: true enables SWR", () => { |
@@ -29,3 +30,44 @@ describe("normalizeRouteRules - swr", () => { |
29 | 30 | expect(withFalse["/api/**"].cache).toBeUndefined(); |
30 | 31 | }); |
31 | 32 | }); |
| 33 | + |
| 34 | +// Regression for GHSA-5w89-w975-hf9q: an encoded traversal like `..%2f` must |
| 35 | +// not let a request escape a `/**` proxy scope once the upstream decodes it. |
| 36 | +describe("isPathInScope", () => { |
| 37 | + it("accepts in-scope paths", () => { |
| 38 | + expect(isPathInScope("/api/orders/list.json", "/api/orders")).toBe(true); |
| 39 | + expect(isPathInScope("/api/orders/", "/api/orders")).toBe(true); |
| 40 | + expect(isPathInScope("/api/orders", "/api/orders")).toBe(true); |
| 41 | + }); |
| 42 | + |
| 43 | + it("rejects encoded slash traversal (%2f)", () => { |
| 44 | + expect(isPathInScope("/api/orders/..%2fadmin%2fconfig.json", "/api/orders")).toBe(false); |
| 45 | + expect(isPathInScope("/api/orders/..%2Fadmin", "/api/orders")).toBe(false); |
| 46 | + }); |
| 47 | + |
| 48 | + it("rejects encoded backslash traversal (%5c)", () => { |
| 49 | + expect(isPathInScope("/api/orders/..%5cadmin", "/api/orders")).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + it("rejects double-encoded dot-segments (%2E%2E)", () => { |
| 53 | + expect(isPathInScope("/api/orders/%2E%2E%2Fadmin", "/api/orders")).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it("rejects literal traversal above scope", () => { |
| 57 | + expect(isPathInScope("/api/orders/../admin", "/api/orders")).toBe(false); |
| 58 | + expect(isPathInScope("/api/orders/../../etc/passwd", "/api/orders")).toBe(false); |
| 59 | + }); |
| 60 | + |
| 61 | + it("keeps traversal confined within scope", () => { |
| 62 | + expect(isPathInScope("/api/orders/foo/../bar", "/api/orders")).toBe(true); |
| 63 | + expect(isPathInScope("/api/orders/foo%2f..%2fbar", "/api/orders")).toBe(true); |
| 64 | + }); |
| 65 | + |
| 66 | + it("does not confuse sibling prefix with scope", () => { |
| 67 | + expect(isPathInScope("/api/ordersX/list.json", "/api/orders")).toBe(false); |
| 68 | + }); |
| 69 | + |
| 70 | + it("allows anything for an empty base (catch-all /**)", () => { |
| 71 | + expect(isPathInScope("/anything/here", "")).toBe(true); |
| 72 | + }); |
| 73 | +}); |
0 commit comments