diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2020-10-27 11:48:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 11:48:45 +0100 |
commit | 30f3b831d31ec47e7d120bcd34194b7b69e6f716 (patch) | |
tree | 6affbc6923ed9cd07f87960d19ab0dab35c9d921 /std/http/file_server_test.ts | |
parent | 9fb4931a95e551c689d4f8ed5d7304f64aafc4d0 (diff) |
fix: path traversal in std/http/file_server.ts (#8134)
Diffstat (limited to 'std/http/file_server_test.ts')
-rw-r--r-- | std/http/file_server_test.ts | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index 3368b2e15..ca8d3b3b2 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -1,5 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { + assert, + assertEquals, + assertStringIncludes, +} from "../testing/asserts.ts"; import { BufReader } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { ServerRequest } from "./server.ts"; @@ -147,6 +151,37 @@ Deno.test("serveFallback", async function (): Promise<void> { } }); +Deno.test("checkPathTraversal", async function (): Promise<void> { + await startFileServer(); + try { + const res = await fetch( + "http://localhost:4507/../../../../../../../..", + ); + assert(res.headers.has("access-control-allow-origin")); + assert(res.headers.has("access-control-allow-headers")); + assertEquals(res.status, 200); + const listing = await res.text(); + assertStringIncludes(listing, "README.md"); + } finally { + await killFileServer(); + } +}); + +Deno.test("checkURIEncodedPathTraversal", async function (): Promise<void> { + await startFileServer(); + try { + const res = await fetch( + "http://localhost:4507/%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..", + ); + assert(res.headers.has("access-control-allow-origin")); + assert(res.headers.has("access-control-allow-headers")); + assertEquals(res.status, 404); + const _ = await res.text(); + } finally { + await killFileServer(); + } +}); + Deno.test("serveWithUnorthodoxFilename", async function (): Promise<void> { await startFileServer(); try { |