Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 0de9caf

Browse files
authored
delete pubcommon test cookie for domainOverride after writing it in all cases (prebid#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.
1 parent 1bbe837 commit 0de9caf

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

modules/pubCommonIdSystem.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function storeData(config, value) {
3737

3838
if (config.storage.type === COOKIE) {
3939
if (storage.cookiesAreEnabled()) {
40-
storage.setCookie(key, value, expiresStr, 'LAX', COOKIE_DOMAIN);
40+
storage.setCookie(key, value, expiresStr, 'LAX', pubCommonIdSubmodule.domainOverride());
4141
}
4242
} else if (config.storage.type === LOCAL_STORAGE) {
4343
if (storage.hasLocalStorage()) {
@@ -282,16 +282,19 @@ export const pubCommonIdSubmodule = {
282282
domainOverride: function () {
283283
const domainElements = document.domain.split('.');
284284
const cookieName = `_gd${Date.now()}`;
285-
for (let i = 0, topDomain; i < domainElements.length; i++) {
285+
for (let i = 0, topDomain, testCookie; i < domainElements.length; i++) {
286286
const nextDomain = domainElements.slice(i).join('.');
287287

288288
// write test cookie
289289
storage.setCookie(cookieName, '1', undefined, undefined, nextDomain);
290290

291291
// read test cookie to verify domain was valid
292-
if (storage.getCookie(cookieName) === '1') {
293-
// delete test cookie
294-
storage.setCookie(cookieName, '', 'Thu, 01 Jan 1970 00:00:01 GMT', undefined, nextDomain);
292+
testCookie = storage.getCookie(cookieName);
293+
294+
// delete test cookie
295+
storage.setCookie(cookieName, '', 'Thu, 01 Jan 1970 00:00:01 GMT', undefined, nextDomain);
296+
297+
if (testCookie === '1') {
295298
// cookie was written successfully using test domain so the topDomain is updated
296299
topDomain = nextDomain;
297300
} else {
@@ -302,6 +305,4 @@ export const pubCommonIdSubmodule = {
302305
}
303306
};
304307

305-
const COOKIE_DOMAIN = pubCommonIdSubmodule.domainOverride();
306-
307308
submodule('userId', pubCommonIdSubmodule);

0 commit comments

Comments
 (0)