Skip to content

Commit ea53f96

Browse files
authored
Merge commit from fork
1 parent 3896fe5 commit ea53f96

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

send.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.
22

3-
import { assertEquals, assertStrictEquals } from "./deps_test.ts";
3+
import {
4+
assertEquals,
5+
assertRejects,
6+
assertStrictEquals,
7+
} from "./deps_test.ts";
48
import {
59
createMockApp,
610
createMockContext,
@@ -13,6 +17,7 @@ import { assert, errors, eTag } from "./deps.ts";
1317
import type { RouteParams } from "./router.ts";
1418
import { send } from "./send.ts";
1519
import { isNode } from "./utils/type_guards.ts";
20+
import { httpErrors } from "./mod.ts";
1621

1722
function setup<
1823
// deno-lint-ignore no-explicit-any
@@ -482,3 +487,16 @@ Deno.test({
482487
context.response.destroy();
483488
},
484489
});
490+
491+
Deno.test({
492+
name: "send - security - decoding paths to subvert checks",
493+
async fn() {
494+
const { context } = setup("/poc%2f../.test.json");
495+
await assertRejects(async () => {
496+
await send(context, context.request.url.pathname, {
497+
root: "./fixtures",
498+
hidden: false,
499+
});
500+
}, httpErrors.NotFound);
501+
},
502+
});

send.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from "./deps.ts";
3131
import type { Response } from "./response.ts";
3232
import { isNode } from "./utils/type_guards.ts";
33-
import { decodeComponent } from "./utils/decode_component.ts";
33+
import { decode } from "./utils/decode.ts";
3434
import { resolvePath } from "./utils/resolve_path.ts";
3535

3636
if (isNode()) {
@@ -179,7 +179,7 @@ export async function send(
179179
root,
180180
} = options;
181181
const trailingSlash = path[path.length - 1] === "/";
182-
path = decodeComponent(path.substring(parse(path).root.length));
182+
path = decode(path.substring(parse(path).root.length));
183183
if (index && trailingSlash) {
184184
path += index;
185185
}

0 commit comments

Comments
 (0)