Skip to content

Commit

Permalink
PBjs Core: added maxNestedIframes option (#6615)
Browse files Browse the repository at this point in the history
* PBjs Core: added maxNestedIframes option

* change default maxNestedIframes to 10

Co-authored-by: Andrea Fassina <andrea.fassina@nativery.com>
  • Loading branch information
2 people authored and idettman committed May 21, 2021
1 parent 7ffd841 commit 533a4fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const DEFAULT_ENABLE_SEND_ALL_BIDS = true;
const DEFAULT_DISABLE_AJAX_TIMEOUT = false;
const DEFAULT_BID_CACHE = false;
const DEFAULT_DEVICE_ACCESS = true;
const DEFAULT_MAX_NESTED_IFRAMES = 10;

const DEFAULT_TIMEOUTBUFFER = 400;

Expand Down Expand Up @@ -200,6 +201,15 @@ export function newConfig() {
this._disableAjaxTimeout = val;
},

// default max nested iframes for referer detection
_maxNestedIframes: DEFAULT_MAX_NESTED_IFRAMES,
get maxNestedIframes() {
return this._maxNestedIframes;
},
set maxNestedIframes(val) {
this._maxNestedIframes = val;
},

_auctionOptions: {},
get auctionOptions() {
return this._auctionOptions;
Expand Down
6 changes: 4 additions & 2 deletions src/refererDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* The information that it tries to collect includes:
* The detected top url in the nav bar,
* Whether it was able to reach the top most window (if for example it was embedded in several iframes),
* The number of iframes it was embedded in if applicable,
* The number of iframes it was embedded in if applicable (by default max ten iframes),
* A list of the domains of each embedded window if applicable.
* Canonical URL which refers to an HTML link element, with the attribute of rel="canonical", found in the <head> element of your webpage
*/

import { config } from './config.js';
import { logWarn } from './utils.js';
import { config } from './config.js';

Expand Down Expand Up @@ -77,6 +78,7 @@ export function detectReferer(win) {
function refererInfo() {
const stack = [];
const ancestors = getAncestorOrigins(win);
const maxNestedIframes = config.getConfig('maxNestedIframes');
let currentWindow;
let bestReferrer;
let bestCanonicalUrl;
Expand Down Expand Up @@ -166,7 +168,7 @@ export function detectReferer(win) {

stack.push(foundReferrer);
level++;
} while (currentWindow !== win.top);
} while (currentWindow !== win.top && level < maxNestedIframes);

stack.reverse();

Expand Down
6 changes: 6 additions & 0 deletions test/spec/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ describe('config API', function () {
expect(getConfig('deviceAccess')).to.be.equal(true);
});

it('sets maxNestedIframes', function () {
expect(getConfig('maxNestedIframes')).to.be.equal(10);
setConfig({ maxNestedIframes: 2 });
expect(getConfig('maxNestedIframes')).to.be.equal(2);
});

it('should log error for invalid priceGranularity', function () {
setConfig({ priceGranularity: '' });
const error = 'Prebid Error: no value passed to `setPriceGranularity()`';
Expand Down

0 comments on commit 533a4fd

Please sign in to comment.