Skip to content

Commit 99fcc1f

Browse files
committed
added tests for encoded dots
1 parent c2a5ef6 commit 99fcc1f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

echo_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ func TestEcho_StaticFS(t *testing.T) {
257257
expectStatus: http.StatusNotFound,
258258
expectBodyStartsWith: "{\"message\":\"Not Found\"}\n",
259259
},
260+
{
261+
name: "do not accept encoded dots in path (%2E%2E is `..`) to traverse within filesystem boundary",
262+
givenPrefix: "/",
263+
givenFs: os.DirFS("_fixture/"),
264+
givenEnablePathUnescapingStaticFiles: false,
265+
whenURL: `/dist/public/%2E%2E/private.txt`, // `/dist/public/../private.txt`
266+
expectStatus: http.StatusNotFound,
267+
expectBodyStartsWith: "{\"message\":\"Not Found\"}\n",
268+
},
269+
{
270+
name: "allow encoded dots in path (%2E%2E is `..`) to traverse within filesystem",
271+
givenPrefix: "/",
272+
givenFs: os.DirFS("_fixture/"),
273+
givenEnablePathUnescapingStaticFiles: true,
274+
whenURL: `/dist/public/%2E%2E/private.txt`, // `/dist/public/../private.txt`
275+
expectStatus: http.StatusOK,
276+
expectBodyStartsWith: "private file",
277+
},
260278
{
261279
name: "do not allow directory traversal (slash - unix separator)",
262280
givenPrefix: "/",

0 commit comments

Comments
 (0)