Skip to content

Commit 20596ca

Browse files
authored
Fix resolveRelUrl() attempting to use invalid URLs (#140)
- just use URL class instead of <a> element for absolute URL resolving (removing old code) - specifically check baseURI for https:// or http:// - only use valid http/https baseURI as base rewriting URL - if passed in doc doesn't have an http/https base URI, check window document, then replay-top document. - fixes #139 - fixes webrecorder/replayweb.page#300 - bump version to 3.7.3
1 parent 00c46c4 commit 20596ca

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webrecorder/wombat",
3-
"version": "3.7.2",
3+
"version": "3.7.3",
44
"main": "index.js",
55
"license": "AGPL-3.0-or-later",
66
"author": "Ilya Kreymer, Webrecorder Software",

src/wombat.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -922,16 +922,31 @@ Wombat.prototype.getFinalUrl = function(useRel, mod, url) {
922922
};
923923

924924
/**
925-
* Converts the supplied relative URL to an absolute URL using an A tag
925+
* Converts the supplied relative URL to an absolute URL using URL class
926926
* @param {string} url
927927
* @param {?Document} doc
928928
* @return {string}
929929
*/
930930
Wombat.prototype.resolveRelUrl = function(url, doc) {
931-
var docObj = doc || this.$wbwindow.document;
932-
var parser = this.makeParser(docObj.baseURI, docObj);
931+
var wombat = this;
932+
933+
function isValidBaseURI(doc) {
934+
if (!doc || !doc.baseURI) {
935+
return false;
936+
}
937+
return (doc.baseURI.startsWith(wombat.HTTPS_PREFIX) || doc.baseURI.startsWith(wombat.HTTP_PREFIX));
938+
}
933939

934-
return new this.URL(url, parser).href;
940+
var baseURI = null;
941+
if (isValidBaseURI(doc)) {
942+
baseURI = doc.baseURI;
943+
} else if (isValidBaseURI(this.$wbwindow.document)) {
944+
baseURI = this.$wbwindow.document.baseURI;
945+
} else {
946+
baseURI = this.$wbwindow.__WB_replay_top.document.baseURI;
947+
}
948+
949+
return new this.URL(url, baseURI).href;
935950
};
936951

937952
/**
@@ -1688,7 +1703,6 @@ Wombat.prototype.rewriteWSURL = function(originalURL) {
16881703
var wsScheme = 'ws://';
16891704
var wssScheme = 'wss://';
16901705

1691-
// proxy mode: If no wb_replay_prefix, only rewrite scheme
16921706
// proxy mode: If no wb_replay_prefix, only rewrite scheme
16931707
if (this.wb_is_proxy) {
16941708
if (

0 commit comments

Comments
 (0)