Skip to content

Commit

Permalink
Merge pull request #457 from salesforce/fix_issue_455
Browse files Browse the repository at this point in the history
fix: remove cookies that expire at epoch time of `0`
  • Loading branch information
colincasey authored Sep 19, 2024
2 parents 1a71340 + 99dc62a commit 039663c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/__tests__/cookieJar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,16 @@ describe('validation errors invoke callbacks', () => {
})
})

it('issue #455 - should expire a cookie with epoch zero', async () => {
const cookieJar = new CookieJar()
await cookieJar.setCookie(
'OptionsTest=FooBar; Expires=Thu, 01 Jan 1970 00:00:00 GMT;',
'http://example.com',
)
const cookies = await cookieJar.getCookies('http://example.com')
expect(cookies.length).toBe(0)
})

function createCookie(
cookieString: string,
options: {
Expand Down
2 changes: 1 addition & 1 deletion lib/cookie/cookieJar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ export class CookieJar {
// deferred from S5.3
// non-RFC: allow retention of expired cookies by choice
const expiryTime = c.expiryTime()
if (expireCheck && expiryTime && expiryTime <= now) {
if (expireCheck && expiryTime != undefined && expiryTime <= now) {
store.removeCookie(c.domain, c.path, c.key, () => {}) // result ignored
return false
}
Expand Down

0 comments on commit 039663c

Please sign in to comment.