Skip to content

Commit

Permalink
delete pubcommon test cookie for domainOverride after writing it in a…
Browse files Browse the repository at this point in the history
…ll 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.
  • Loading branch information
smenzer authored Nov 10, 2020
1 parent 1bbe837 commit 0de9caf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions modules/pubCommonIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 {
Expand All @@ -302,6 +305,4 @@ export const pubCommonIdSubmodule = {
}
};

const COOKIE_DOMAIN = pubCommonIdSubmodule.domainOverride();

submodule('userId', pubCommonIdSubmodule);

0 comments on commit 0de9caf

Please sign in to comment.