Skip to content

Commit

Permalink
adding secure flag for cookies that starts with __Secure (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
prklm10 authored Sep 18, 2024
1 parent 8c61c0a commit d0ba2dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ function parseCookies(cookiesStr) {

return cookiesStr.split('; ').map(c => {
const eqIdx = c.indexOf('=');
return { name: c.substring(0, eqIdx), value: c.substring(eqIdx + 1) };
const name = c.substring(0, eqIdx);
const value = c.substring(eqIdx + 1);
const cookieObj = { name, value };

if (name.startsWith('__Secure')) {
cookieObj.secure = true;
}
return cookieObj;
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1367,15 +1367,15 @@ describe('Discovery', () => {
url: 'http://localhost:8000',
domSnapshot: {
html: testDOM,
cookies: 'test-cookie=value'
cookies: '__Secure-test-cookie=value'
}
});

expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Snapshot taken: mmm cookies'
]));

expect(cookie).toEqual('test-cookie=value');
expect(cookie).toEqual('__Secure-test-cookie=value');
});

it('does not use cookie if empty cookies is passed (in case of httponly)', async () => {
Expand Down

0 comments on commit d0ba2dd

Please sign in to comment.