Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow-up to #161: #162

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.7.9",
"version": "3.7.10",
"main": "index.js",
"license": "AGPL-3.0-or-later",
"author": "Ilya Kreymer, Webrecorder Software",
Expand Down
55 changes: 21 additions & 34 deletions src/wombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,9 @@ Wombat.prototype.overridePropExtract = function(proto, prop) {
var new_getter = function () {
var obj = wombat.proxyToObj(this);
var res = orig_getter.call(obj);
if (obj.__WB_no_unrewrite) {
return res;
}
return wombat.extractOriginalURL(res);
};
this.defGetterProp(proto, prop, new_getter);
Expand Down Expand Up @@ -4612,25 +4615,15 @@ Wombat.prototype.initHTTPOverrides = function() {

if (input instanceof Request) {
var new_url = wombat.rewriteUrl(input.url);
var real_url = input.__WB_real_url;
// if already a Request with rewritten url, just use that
if (new_url === input.url || new_url === real_url || new_url === wombat.$wbwindow.location.origin + real_url) {
input.__WB_no_unrewrite = true;
if (new_url === input.url) {
request = input;
} else {
request = new Request(new_url, input);
}
delete input.__WB_no_unrewrite;
} else {
input = wombat.rewriteUrl(input.toString());

if (!init_opts) {
init_opts = {};
}
if (init_opts.credentials === undefined) {
try {
init_opts.credentials = 'include';
} catch(e) {}
}

request = new Request(input, init_opts);
}

Expand Down Expand Up @@ -4665,30 +4658,24 @@ Wombat.prototype.initHTTPOverrides = function() {
}
break;
}
const props = ['cache', 'headers', 'integrity',
'keepalive', 'method', 'mode', 'redirect',
'referrerPolicy', 'signal'
];

const newOpts = {};

for (const prop of props) {
newOpts[prop] = newInitOpts[prop];
}

newOpts.credentials = 'include';

if (newInitOpts.referrer) {
newOpts.referrer = wombat.rewriteUrl(newInitOpts.referrer);
let unrwSet = false;
// make a duplicate object to override referrer
if (newInitOpts && newInitOpts.referrer) {
var newReferrer = wombat.rewriteUrl(newInitOpts.referrer);
if (newReferrer !== newInitOpts.referrer) {
if (newInitOpts instanceof Request) {
newInitOpts.__WB_no_unrewrite = true;
unrwSet = true;
} else {
newInitOpts.referrer = newReferrer;
}
}
}

if (newInitOpts.duplex && newInitOpts.body) {
newOpts.body = newInitOpts.body;
newOpts.duplex = newInitOpts.duplex;
var request = new Request_(newInput, newInitOpts);
if (unrwSet) {
delete newInitOpts.__WB_no_unrewrite;
}

var request = new Request_(newInput, newOpts);
request.__WB_real_url = newInput;
return request;
};
})(this.$wbwindow.Request);
Expand Down
25 changes: 23 additions & 2 deletions test/overrides-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,36 @@ test('fetch: should rewrite the input argument when it is an Request object, als
const data = await response.json();
return {url: data.url,
rwUrl: request.url,
realUrl: request.__WB_real_url,
respURL: response.url};
});
t.is(result.rwUrl, 'https://tests.wombat.io/test');
t.is(result.realUrl, '/live/20180803160549mp_/https://tests.wombat.io/test');
t.is(result.url, '/live/20180803160549mp_/https://tests.wombat.io/test');
t.is(result.respURL, 'https://tests.wombat.io/test');
});

test('fetch: Request.referrer is rewritten across multiple copies of Request', async t => {
const { sandbox, server } = t.context;
const result = await sandbox.evaluate(async () => {
let to;
let A = new Request('/test', {'referrer': '/abc'});
let B = new Request('/test', A);
let C = new Request(B, {'referrer': '/xyz'});
let D = new Request({'url': '/test', 'referrer': '/cde'}, C);
D.__WB_no_unrewrite = true;

return {A: A.referrer,
B: B.referrer,
C: C.referrer,
D: D.referrer
};
});
t.is(result.A, 'https://tests.wombat.io/abc');
t.is(result.B, 'https://tests.wombat.io/abc');
t.is(result.C, 'https://tests.wombat.io/xyz');
t.is(result.D, 'http://localhost:3030/live/20180803160549mp_/https://tests.wombat.io/xyz');
});


test('fetch: should rewrite the input argument when it is a object, but return original', async t => {
const { sandbox, server } = t.context;
const result = await sandbox.evaluate(async () => {
Expand Down
Loading