From 8be766abcba0fe148b463a51e8cb6357cc2105e8 Mon Sep 17 00:00:00 2001 From: Pradum Kumar Date: Wed, 18 Sep 2024 19:08:20 +0530 Subject: [PATCH] adding secure flag for cookies that starts with __Secure (#1730) --- packages/core/src/discovery.js | 9 ++++++++- packages/core/test/discovery.test.js | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/src/discovery.js b/packages/core/src/discovery.js index 801f6594e..c561938d9 100644 --- a/packages/core/src/discovery.js +++ b/packages/core/src/discovery.js @@ -93,7 +93,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; }); } diff --git a/packages/core/test/discovery.test.js b/packages/core/test/discovery.test.js index 63e4b07ff..c29ad8711 100644 --- a/packages/core/test/discovery.test.js +++ b/packages/core/test/discovery.test.js @@ -1367,7 +1367,7 @@ describe('Discovery', () => { url: 'http://localhost:8000', domSnapshot: { html: testDOM, - cookies: 'test-cookie=value' + cookies: '__Secure-test-cookie=value' } }); @@ -1375,7 +1375,7 @@ describe('Discovery', () => { '[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 () => {