From 447f3fe410c85e153a518474789682f2accab740 Mon Sep 17 00:00:00 2001 From: "Yasser A.Idrissi" Date: Tue, 1 Dec 2020 14:23:03 +0100 Subject: feat(std/http): Add Cookie value validation (#8471) --- std/http/cookie_test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'std/http/cookie_test.ts') diff --git a/std/http/cookie_test.ts b/std/http/cookie_test.ts index bc45b2996..09d6764af 100644 --- a/std/http/cookie_test.ts +++ b/std/http/cookie_test.ts @@ -65,6 +65,44 @@ Deno.test({ }, }); +Deno.test({ + name: "Cookie Value Validation", + fn(): void { + const res: Response = {}; + const tokens = [ + "1f\tWa", + "\t", + "1f Wa", + "1f;Wa", + '"1fWa', + "1f\\Wa", + '1f"Wa', + '"', + "1fWa\u0005", + "1f\u0091Wa", + ]; + res.headers = new Headers(); + tokens.forEach((value) => { + assertThrows( + (): void => { + setCookie( + res, + { + name: "Space", + value, + httpOnly: true, + secure: true, + maxAge: 3, + }, + ); + }, + Error, + "RFC2616 cookie 'Space'", + ); + }); + }, +}); + Deno.test({ name: "Cookie Path Validation", fn(): void { -- cgit v1.2.3