Skip to content

Commit

Permalink
fix: clear cookie headers too on redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
jd1378 committed Jul 20, 2024
1 parent 5feaa82 commit e2d40f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@
"deno.unstable": true,
"deno.lint": true,
"debug.javascript.unmapMissingSources": true,
"deno.import_intellisense_origins": {
"https://deno.land": true
}
"deno.codeLens.test": true,
}
13 changes: 13 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions fetch_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function wrapFetch(options?: WrapFetchOptions): typeof fetch {
if (cookieString.length) {
reqHeaders.set("cookie", cookieString);
}

reqHeaders.delete("cookie2"); // Remove cookie2 if it exists, It's deprecated

interceptedInit.headers = reqHeaders;
Expand Down Expand Up @@ -129,7 +129,10 @@ export function wrapFetch(options?: WrapFetchOptions): typeof fetch {

// Do not forward sensitive headers to third-party domains.
if (!isDomainOrSubdomain(originalRequestUrl, redirectUrl)) {
for (const name of ["authorization", "www-authenticate"]) { // cookie headers are handled differently
// cookie headers are handled differently
for (
const name of ["authorization", "www-authenticate", "cookie", "cookie2"]
) {
filteredHeaders.delete(name);
}
}
Expand Down
4 changes: 1 addition & 3 deletions fetch_wrapper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ Deno.test("doesn't send sensitive headers after redirect to different domains",
"request had `authorization` in headers",
);
assertFalse(
resHeaders.get("cookie"),
resHeaders.has("cookie"),
"`cookie` header is not empty",
);
assertFalse(
Expand Down Expand Up @@ -606,8 +606,6 @@ Deno.test("handles path redirections", async () => {
{ method: "GET" },
).then((r) => r.text());

console.log(res);

assertEquals(
res,
"foo",
Expand Down

0 comments on commit e2d40f5

Please sign in to comment.