Skip to content
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
23 changes: 23 additions & 0 deletions lib/__tests__/cookiePrefixes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
`Cookie has __Host prefix but either Secure or HostOnly attribute is not set or Path is not '/'`,
)
})

it('should error when there is no explicit Path attribute', async () => {
await expect(
cookieJar.setCookie('__Host-SID=12345; Secure', secureUrl, {}),
).rejects.toThrow(
`Cookie has __Host prefix but either Secure or HostOnly attribute is not set or Path is not '/'`,
)
})

it('should work with an explicit Path of /', async () => {
await cookieJar.setCookie(
'__Host-SID=12345; Secure; Path=/',
secureUrl,
{},
)
const cookies = await cookieJar.getCookies(secureUrl)
expect(cookies).toEqual([
expect.objectContaining({
key: '__Host-SID',
value: '12345',
}),
])
})
})
})

Expand Down
3 changes: 2 additions & 1 deletion lib/cookie/cookieJar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ function isHostPrefixConditionMet(cookie: Cookie): boolean {
cookie.secure &&
cookie.hostOnly &&
cookie.path != null &&
cookie.path === '/',
cookie.path === '/' &&
!cookie.pathIsDefault,
)
)
}
Expand Down
Loading