Skip to content

Commit

Permalink
Location Assignment Check (#77)
Browse files Browse the repository at this point in the history
* location assignment check: when assigning to location, check if same object is in the arguments array and skip to avoid some false positive location assignments, partial fix for webrecorder/pywb#684

* test: add overrides test to ensure local assign via __WB_check_loc() does not trigger redirect

* bump to 3.3.5
  • Loading branch information
ikreymer authored Nov 27, 2021
1 parent e0567d5 commit d877812
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wombat",
"version": "3.3.4",
"version": "3.3.5",
"main": "index.js",
"license": "AGPL-3.0-or-later",
"author": "Ilya Kreymer, Webrecorder Software",
Expand Down
12 changes: 11 additions & 1 deletion src/wombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5123,8 +5123,18 @@ Wombat.prototype.initProtoPmOrigin = function(win) {
});
} catch (e) {}

win.__WB_check_loc = function(loc) {
win.__WB_check_loc = function(loc, args) {
if (loc instanceof Location || loc instanceof WombatLocation) {
// args, if provided, should be the 'arguments' from calling function
// check if the location is actually a locally passed in argument,
// if so, don't assign to global location
if (args) {
for (var i = 0; i < args.length; i++) {
if (loc === args[i]) {
return {};
}
}
}
return this.WB_wombat_location;
} else {
return {};
Expand Down
19 changes: 19 additions & 0 deletions test/overrides-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ test('WombatLocation: should have a Symbol.toStringTag value of "Location"', asy
);
});

test('WombatLocation should not navigate when assigning to local object', async t => {
const { sandbox, server } = t.context;
const result = await sandbox.evaluate(() => {
let location = window.WB_wombat_location;

function navTest(location) {
location = ((self.__WB_check_loc && self.__WB_check_loc(location, arguments)) || {}).href = location.protocol + '//' + location.hostname + '/it';
return location;
}

return navTest(location);
});
t.is(
result,
'https://tests.wombat.io/it',
'the page navigated away and did not return a URL'
);
});

test('WombatLocation browser navigation control: should rewrite Location.replace usage', async t => {
const { sandbox, server } = t.context;
const [navigationResponse] = await Promise.all([
Expand Down

0 comments on commit d877812

Please sign in to comment.