From c1d2b197b29daa017060f7f8ab0f215927c3eed6 Mon Sep 17 00:00:00 2001 From: Thorsten Krug Date: Mon, 16 Nov 2020 10:21:04 +0100 Subject: [PATCH] Remove cookie domain as it could be munged. --- capture/engine_scripts/cookies.json | 1 - capture/engine_scripts/puppet/loadCookies.js | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/capture/engine_scripts/cookies.json b/capture/engine_scripts/cookies.json index b59400d7e..0146751b3 100644 --- a/capture/engine_scripts/cookies.json +++ b/capture/engine_scripts/cookies.json @@ -1,6 +1,5 @@ [ { - "domain": ".www.yourdomain.com", "path": "/", "name": "yourCookieName", "value": "yourCookieValue", diff --git a/capture/engine_scripts/puppet/loadCookies.js b/capture/engine_scripts/puppet/loadCookies.js index f9bdd4de5..7e81eee01 100644 --- a/capture/engine_scripts/puppet/loadCookies.js +++ b/capture/engine_scripts/puppet/loadCookies.js @@ -1,7 +1,7 @@ const fs = require('fs'); module.exports = async (page, scenario) => { - let cookies = []; + const cookies = []; const cookiePath = scenario.cookiePath; // READ COOKIES FROM FILE IF EXISTS @@ -9,10 +9,14 @@ module.exports = async (page, scenario) => { cookies = JSON.parse(fs.readFileSync(cookiePath)); } - // MUNGE COOKIE DOMAIN + // Inject cookie domain, url, secure from scenario url. + const url = new URL(scenario.url); cookies = cookies.map(cookie => { - cookie.url = 'https://' + cookie.domain; - delete cookie.domain; + cookie.url = `${url.protocol}//${url.hostname}`; + cookie.domain = url.hostname; + if(url.protocol === 'https:') { + cookie.secure = true; + } return cookie; });