Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify cookie name & update SameSite type #4685

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions std/http/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export interface Cookie {
unparsed?: string[];
}

export type SameSite = "Strict" | "Lax";
export type SameSite = "Strict" | "Lax" | "None";

function toString(cookie: Cookie): string {
if (!cookie.name) {
return "";
}
const out: string[] = [];
out.push(`${cookie.name}=${cookie.value}`);

Expand Down Expand Up @@ -115,7 +118,10 @@ export function setCookie(res: Response, cookie: Cookie): void {
// TODO (zekth) : Add proper parsing of Set-Cookie headers
// Parsing cookie headers to make consistent set-cookie header
// ref: https://tools.ietf.org/html/rfc6265#section-4.1.1
res.headers.append("Set-Cookie", toString(cookie));
const v = toString(cookie);
if (v) {
res.headers.append("Set-Cookie", v);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions std/http/cookie_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,9 @@ test({
res.headers.get("Set-Cookie"),
"cookie-1=value-1; Secure, cookie-2=value-2; Max-Age=3600"
);

res.headers = new Headers();
setCookie(res, { name: "", value: "" });
assertEquals(res.headers.get("Set-Cookie"), null);
},
});