Skip to content

Commit c164f76

Browse files
Isaac A. DettmannakamotoChandra PrakashEric HarperTJ Eastmond
authored and
mi.chen
committed
Add enforcement for deviceAccess (prebid#4913)
* Add microadBidAdapter * Remove unnecessary encodeURIComponent from microadBidAdapter * Submit Advangelists Prebid Adapter * Submit Advangelists Prebid Adapter 1.1 * Correct procudtion endpoint for prebid * analytics update with wrapper name * reverted error merge * update changed default value of netRevenue to true * Re-add rubicon analytics without deprecated getTopWindowUrl util * Cache referrer on auction_init instead of bid_requested * add config for deviceAccess enforcement in utils getCookie setCookie and hasLocalStorage * add tests, and updates to names/comments * add deviceAccess enforcement to util method cookiesAreEnabled * update to adspendBidAdapter for device access enforcement * update to pubCommonId for device access enforcement * update widespaceBidAdapter for device access enforcement. updated utils storage methods with jsdoc typing, hasLocalStorage changed to only return boolean type * update to digiTrustIdSystem for device access enforcement * updated utils.setCookie signature, adding a 'domain' argument. update to invibesBidAdapter for device access enforcement * updated utils to group similar storage methods * updated kargoBidAdapter for add-enforcement-device-access * update to minimize changes in adapters using browser storage * updated modules with localStorage or cookie methods to use utils * updated invibesBidAdapter use of storage methods to use utils * fix for wrong obj reference for date string * revert accidental change to package.json * fix linting error, trailing comma. removed unnecessary cookie get set functions and replaced with util methods * reverted change to removed extra methods since it breaks unit test * fix for pubcommonidsystem id generation * update jsdoc param 'domain' * Update adagioBidAdapter.js merging changes from prebid#4978 * Removing encoding in DT encId We need to get moving on this merge, so I made an update -- the encId() function appears to be necessary to stringify and btoa() the ID. Just removed the layer of URL encoding in that function as duplicate of what happens in the PBJS setCookie fn. Co-authored-by: nakamoto <[email protected]> Co-authored-by: Chandra Prakash <[email protected]> Co-authored-by: Eric Harper <[email protected]> Co-authored-by: TJ Eastmond <[email protected]> Co-authored-by: Mark Monday <[email protected]> Co-authored-by: msm0504 <[email protected]> Co-authored-by: bretg <[email protected]>
1 parent 8e88c5e commit c164f76

28 files changed

+211
-129
lines changed

modules/adagioBidAdapter.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ pV6EP3MTLosuUEpLaQIDAQAB
2222

2323
export function getAdagioScript() {
2424
try {
25-
const w = utils.getWindowTop();
26-
const ls = w.localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY);
25+
const ls = utils.getDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY);
2726

2827
if (!ls) {
2928
utils.logWarn('Adagio Script not found');
@@ -34,7 +33,7 @@ export function getAdagioScript() {
3433

3534
if (!hashRgx.test(ls)) {
3635
utils.logWarn('No hash found in Adagio script');
37-
w.localStorage.removeItem(ADAGIO_LOCALSTORAGE_KEY);
36+
utils.removeDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY);
3837
} else {
3938
const r = ls.match(hashRgx);
4039
const hash = r[2];
@@ -48,7 +47,7 @@ export function getAdagioScript() {
4847
Function(ls)(); // eslint-disable-line no-new-func
4948
} else {
5049
utils.logWarn('Invalid Adagio script found');
51-
w.localStorage.removeItem(ADAGIO_LOCALSTORAGE_KEY);
50+
utils.removeDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY);
5251
}
5352
}
5453
} catch (err) {

modules/adkernelAdnAnalyticsAdapter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ const ORGANIC = '(organic)';
175175

176176
export let storage = {
177177
getItem: (name) => {
178-
return localStorage.getItem(name);
178+
return utils.getDataFromLocalStorage(name);
179179
},
180180
setItem: (name, value) => {
181-
localStorage.setItem(name, value);
181+
utils.setDataInLocalStorage(name, value);
182182
}
183183
};
184184

modules/adspendBidAdapter.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const BIDDER_CODE = 'adspend';
88
const BID_URL = 'https://rtb.com.ru/headerbidding-bid';
99
const SYNC_URL = 'https://rtb.com.ru/headerbidding-sync?uid={UUID}';
1010
const COOKIE_NAME = 'hb-adspend-id';
11-
const UUID_LEN = 36;
1211
const TTL = 10000;
1312
const RUB = 'RUB';
1413
const FIRST_PRICE = 1;
@@ -146,16 +145,14 @@ export const spec = {
146145
}
147146

148147
const getUserID = () => {
149-
const i = document.cookie.indexOf(COOKIE_NAME);
148+
const i = utils.getCookie(COOKIE_NAME);
150149

151-
if (i === -1) {
150+
if (i === null) {
152151
const uuid = utils.generateUUID();
153-
document.cookie = `${COOKIE_NAME}=${uuid}; path=/`;
152+
utils.setCookie(COOKIE_NAME, uuid);
154153
return uuid;
155154
}
156-
157-
const j = i + COOKIE_NAME.length + 1;
158-
return document.cookie.substring(j, j + UUID_LEN);
155+
return i;
159156
};
160157

161158
const getFormats = arr => arr.map((s) => {

modules/criteoBidAdapter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export function tryGetCriteoFastBid() {
436436
try {
437437
const fastBidStorageKey = 'criteo_fast_bid';
438438
const hashPrefix = '// Hash: ';
439-
const fastBidFromStorage = localStorage.getItem(fastBidStorageKey);
439+
const fastBidFromStorage = utils.getDataFromLocalStorage(fastBidStorageKey);
440440

441441
if (fastBidFromStorage !== null) {
442442
// The value stored must contain the file's encrypted hash as first line
@@ -445,7 +445,7 @@ export function tryGetCriteoFastBid() {
445445

446446
if (firstLine.substr(0, hashPrefix.length) !== hashPrefix) {
447447
utils.logWarn('No hash found in FastBid');
448-
localStorage.removeItem(fastBidStorageKey);
448+
utils.removeDataFromLocalStorage(fastBidStorageKey);
449449
} else {
450450
// Remove the hash part from the locally stored value
451451
const publisherTagHash = firstLine.substr(hashPrefix.length);
@@ -459,7 +459,7 @@ export function tryGetCriteoFastBid() {
459459
utils.insertElement(script);
460460
} else {
461461
utils.logWarn('Invalid Criteo FastBid found');
462-
localStorage.removeItem(fastBidStorageKey);
462+
utils.removeDataFromLocalStorage(fastBidStorageKey);
463463
}
464464
}
465465
}

modules/digiTrustIdSystem.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function encId(id) {
6969
if (typeof (id) !== 'string') {
7070
id = JSON.stringify(id);
7171
}
72-
return encodeURIComponent(btoa(id));
72+
return btoa(id);
7373
} catch (ex) {
7474
return id;
7575
}
@@ -83,8 +83,7 @@ function writeDigiId(id) {
8383
var key = 'DigiTrust.v1.identity';
8484
var date = new Date();
8585
date.setTime(date.getTime() + 604800000);
86-
var exp = 'expires=' + date.toUTCString();
87-
document.cookie = key + '=' + encId(id) + '; ' + exp + '; path=/;SameSite=none;';
86+
utils.setCookie(key, encId(id), date.toUTCString(), 'none');
8887
}
8988

9089
/**

modules/fintezaAnalyticsAdapter.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function getUniqId() {
4646
let uniq = cookies[ UNIQ_ID_KEY ];
4747
if (!uniq) {
4848
try {
49-
if (window.localStorage) {
50-
uniq = window.localStorage.getItem(UNIQ_ID_KEY) || '';
49+
if (utils.hasLocalStorage()) {
50+
uniq = utils.getDataFromLocalStorage(UNIQ_ID_KEY) || '';
5151
isUniqFromLS = true;
5252
}
5353
} catch (b) {}
@@ -62,7 +62,7 @@ function getUniqId() {
6262
expires.setFullYear(expires.getFullYear() + 10);
6363

6464
try {
65-
document.cookie = UNIQ_ID_KEY + '=' + uniq + '; path=/; expires=' + expires.toUTCString();
65+
utils.setCookie(UNIQ_ID_KEY, uniq, expires.toUTCString());
6666
} catch (e) {}
6767
}
6868

@@ -90,7 +90,7 @@ function initFirstVisit() {
9090
now.setFullYear(now.getFullYear() + 20);
9191

9292
try {
93-
document.cookie = FIRST_VISIT_DATE + '=' + visitDate + '; path=/; expires=' + now.toUTCString();
93+
utils.setCookie(FIRST_VISIT_DATE, visitDate, now.toUTCString());
9494
} catch (e) {}
9595
}
9696

@@ -110,7 +110,7 @@ function parseCookies(cookie) {
110110
let param, value;
111111
let i, j;
112112

113-
if (!cookie) {
113+
if (!cookie || !utils.cookiesAreEnabled()) {
114114
return {};
115115
}
116116

@@ -203,7 +203,7 @@ function initSession() {
203203
}
204204

205205
try {
206-
document.cookie = SESSION_ID + '=' + sessionId + '; path=/; expires=' + expires.toUTCString();
206+
utils.setCookie(SESSION_ID, sessionId, expires.toUTCString());
207207
} catch (e) {}
208208

209209
return {
@@ -249,10 +249,10 @@ function saveTrackRequestTime() {
249249
const expires = new Date(now + SESSION_DURATION);
250250

251251
try {
252-
if (window.localStorage) {
253-
window.localStorage.setItem(TRACK_TIME_KEY, now.toString());
252+
if (utils.hasLocalStorage()) {
253+
utils.setDataInLocalStorage(TRACK_TIME_KEY, now.toString());
254254
} else {
255-
document.cookie = TRACK_TIME_KEY + '=' + now + '; path=/; expires=' + expires.toUTCString();
255+
utils.setCookie(TRACK_TIME_KEY, now.toString(), expires.toUTCString());
256256
}
257257
} catch (a) {}
258258
}
@@ -261,9 +261,9 @@ function getTrackRequestLastTime() {
261261
let cookie;
262262

263263
try {
264-
if (window.localStorage) {
264+
if (utils.hasLocalStorage()) {
265265
return parseInt(
266-
window.localStorage.getItem(TRACK_TIME_KEY) || 0,
266+
utils.getDataFromLocalStorage(TRACK_TIME_KEY) || 0,
267267
10,
268268
);
269269
}

modules/invibesBidAdapter.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,14 @@ function getCappedCampaignsAsString() {
276276

277277
let loadData = function () {
278278
try {
279-
return JSON.parse(localStorage.getItem(key)) || {};
279+
return JSON.parse(utils.getDataFromLocalStorage(key)) || {};
280280
} catch (e) {
281281
return {};
282282
}
283283
};
284284

285285
let saveData = function (data) {
286-
localStorage.setItem(key, JSON.stringify(data));
286+
utils.setDataInLocalStorage(key, JSON.stringify(data));
287287
};
288288

289289
let clearExpired = function () {
@@ -319,7 +319,7 @@ function getCappedCampaignsAsString() {
319319
const noop = function () { };
320320

321321
function initLogger() {
322-
if (localStorage && localStorage.InvibesDEBUG) {
322+
if (utils.hasLocalStorage() && localStorage.InvibesDEBUG) {
323323
return window.console;
324324
}
325325

@@ -384,6 +384,7 @@ invibes.Uid = {
384384

385385
let cookieDomain;
386386
invibes.getCookie = function (name) {
387+
if (!utils.cookiesAreEnabled()) { return; }
387388
let i, x, y;
388389
let cookies = document.cookie.split(';');
389390
for (i = 0; i < cookies.length; i++) {
@@ -397,16 +398,15 @@ invibes.getCookie = function (name) {
397398
};
398399

399400
invibes.setCookie = function (name, value, exdays, domain) {
401+
if (!utils.cookiesAreEnabled()) { return; }
400402
let whiteListed = name == 'ivNoCookie' || name == 'IvbsCampIdsLocal';
401403
if (invibes.noCookies && !whiteListed && (exdays || 0) >= 0) { return; }
402404
if (exdays > 365) { exdays = 365; }
403405
domain = domain || cookieDomain;
404406
let exdate = new Date();
405407
let exms = exdays * 24 * 60 * 60 * 1000;
406408
exdate.setTime(exdate.getTime() + exms);
407-
let cookieValue = value + ((!exdays) ? '' : '; expires=' + exdate.toUTCString());
408-
cookieValue += ';domain=' + domain + ';path=/';
409-
document.cookie = name + '=' + cookieValue;
409+
utils.setCookie(name, value, exdate.toUTCString(), undefined, domain);
410410
};
411411

412412
let detectTopmostCookieDomain = function () {

modules/kargoBidAdapter.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export const spec = {
9898

9999
// PRIVATE
100100
_readCookie(name) {
101+
if (!utils.cookiesAreEnabled()) {
102+
return null;
103+
}
101104
let nameEquals = `${name}=`;
102105
let cookies = document.cookie.split(';');
103106

@@ -170,7 +173,7 @@ export const spec = {
170173

171174
_getLocalStorageSafely(key) {
172175
try {
173-
return localStorage.getItem(key);
176+
return utils.getDataFromLocalStorage(key);
174177
} catch (e) {
175178
return null;
176179
}

modules/mantisBidAdapter.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {registerBidder} from '../src/adapters/bidderFactory.js';
2+
import * as utils from '../src/utils.js';
23

34
function inIframe() {
45
try {
@@ -92,9 +93,9 @@ function storeUuid(uuid) {
9293
return false;
9394
}
9495
window.mantis_uuid = uuid;
95-
if (window.localStorage) {
96+
if (utils.hasLocalStorage()) {
9697
try {
97-
window.localStorage.setItem('mantis:uuid', uuid);
98+
utils.setDataInLocalStorage('mantis:uuid', uuid);
9899
} catch (ex) {
99100
}
100101
}
@@ -175,8 +176,8 @@ function buildMantisUrl(path, data, domain) {
175176
}
176177
if (window.mantis_uuid) {
177178
params.uuid = window.mantis_uuid;
178-
} else if (window.localStorage) {
179-
var localUuid = window.localStorage.getItem('mantis:uuid');
179+
} else if (utils.hasLocalStorage()) {
180+
var localUuid = utils.getDataFromLocalStorage('mantis:uuid');
180181
if (localUuid) {
181182
params.uuid = localUuid;
182183
}

modules/mgidBidAdapter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ function getLanguage() {
342342

343343
function getLocalStorageSafely(key) {
344344
try {
345-
return localStorage.getItem(key);
345+
return utils.getDataFromLocalStorage(key);
346346
} catch (e) {
347347
return null;
348348
}
349349
}
350350

351351
function setLocalStorageSafely(key, val) {
352352
try {
353-
return localStorage.setItem(key, val);
353+
return utils.setDataInLocalStorage(key, val);
354354
} catch (e) {
355355
return null;
356356
}

modules/nanointeractiveBidAdapter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function createSingleBidRequest(bid, bidderRequest) {
9797

9898
function createSingleBidResponse(serverBid) {
9999
if (serverBid.userId) {
100-
localStorage.setItem('lsUserId', serverBid.userId);
100+
utils.setDataInLocalStorage('lsUserId', serverBid.userId);
101101
}
102102
return {
103103
requestId: serverBid.id,
@@ -147,8 +147,8 @@ function getEndpointUrl() {
147147
}
148148

149149
function getLsUserId() {
150-
if (localStorage.getItem('lsUserId') != null) {
151-
return localStorage.getItem('lsUserId');
150+
if (utils.getDataFromLocalStorage('lsUserId') != null) {
151+
return utils.getDataFromLocalStorage('lsUserId');
152152
}
153153
return null;
154154
}

modules/newborntownWebBidAdapter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ export const spec = {
5353
return null;
5454
}
5555
var guid;
56-
if (localStorage.getItem('sax_user_id') == null) {
57-
localStorage.setItem('sax_user_id', generateGUID())
56+
if (utils.getDataFromLocalStorage('sax_user_id') == null) {
57+
utils.setDataInLocalStorage('sax_user_id', generateGUID())
5858
}
59-
guid = localStorage.getItem('sax_user_id')
59+
guid = utils.getDataFromLocalStorage('sax_user_id')
6060
utils._each(validBidRequests, function(bidRequest) {
6161
const bidRequestObj = bidRequest.params
6262
var req = {

modules/orbidderBidAdapter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {detectReferer} from '../src/refererDetection.js';
22
import {ajax} from '../src/ajax.js';
33
import {registerBidder} from '../src/adapters/bidderFactory.js';
4+
import * as utils from '../src/utils.js';
45

56
export const spec = {
67
code: 'orbidder',
78
bidParams: {},
89
orbidderHost: (() => {
910
let ret = 'https://orbidder.otto.de';
1011
try {
11-
ret = localStorage.getItem('ov_orbidder_host') || ret;
12+
ret = utils.getDataFromLocalStorage('ov_orbidder_host') || ret;
1213
} catch (e) {
1314
}
1415
return ret;

0 commit comments

Comments
 (0)