From 0de9caf66128a42b68f7da514707a238305c5a4a Mon Sep 17 00:00:00 2001 From: Scott Menzer Date: Tue, 10 Nov 2020 18:29:26 +0100 Subject: [PATCH] delete pubcommon test cookie for domainOverride after writing it in all cases (#5943) * delete pubcommon test cookie after writing it in all cases, not just when it is found again * fix lunamediahbBidAdapter lint issue * call domainOverride only when needed in the module, not ahead of time when the module is registered. --- modules/pubCommonIdSystem.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/pubCommonIdSystem.js b/modules/pubCommonIdSystem.js index 51b4335fe60..919e735d34e 100644 --- a/modules/pubCommonIdSystem.js +++ b/modules/pubCommonIdSystem.js @@ -37,7 +37,7 @@ function storeData(config, value) { if (config.storage.type === COOKIE) { if (storage.cookiesAreEnabled()) { - storage.setCookie(key, value, expiresStr, 'LAX', COOKIE_DOMAIN); + storage.setCookie(key, value, expiresStr, 'LAX', pubCommonIdSubmodule.domainOverride()); } } else if (config.storage.type === LOCAL_STORAGE) { if (storage.hasLocalStorage()) { @@ -282,16 +282,19 @@ export const pubCommonIdSubmodule = { domainOverride: function () { const domainElements = document.domain.split('.'); const cookieName = `_gd${Date.now()}`; - for (let i = 0, topDomain; i < domainElements.length; i++) { + for (let i = 0, topDomain, testCookie; i < domainElements.length; i++) { const nextDomain = domainElements.slice(i).join('.'); // write test cookie storage.setCookie(cookieName, '1', undefined, undefined, nextDomain); // read test cookie to verify domain was valid - if (storage.getCookie(cookieName) === '1') { - // delete test cookie - storage.setCookie(cookieName, '', 'Thu, 01 Jan 1970 00:00:01 GMT', undefined, nextDomain); + testCookie = storage.getCookie(cookieName); + + // delete test cookie + storage.setCookie(cookieName, '', 'Thu, 01 Jan 1970 00:00:01 GMT', undefined, nextDomain); + + if (testCookie === '1') { // cookie was written successfully using test domain so the topDomain is updated topDomain = nextDomain; } else { @@ -302,6 +305,4 @@ export const pubCommonIdSubmodule = { } }; -const COOKIE_DOMAIN = pubCommonIdSubmodule.domainOverride(); - submodule('userId', pubCommonIdSubmodule);