1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

JS proxy fix (#229)

* proxy access fixes:
- catch proxy access (in case cross-domain, eg. from service worker)
- document.location access falls back to defaultView._WB_wombat_location if not available
- use obj_to_proxy(), proxy_to_obj() wrappers access, catch exceptions
This commit is contained in:
Ilya Kreymer 2017-08-07 20:00:30 -07:00 committed by GitHub
parent 39b5630f7b
commit 33ba67646b

View File

@ -899,9 +899,7 @@ var _WBWombat = function($wbwindow, wbinfo) {
if (orig_getter) {
var new_getter = function() {
var res = orig_getter.call(this);
res = (res && res._WB_wombat_obj_proxy) || res;
return res;
return obj_to_proxy(orig_getter.call(this));
}
def_prop(proto, prop, undefined, new_getter);
@ -1720,11 +1718,9 @@ var _WBWombat = function($wbwindow, wbinfo) {
var getter = function() {
init_iframe_wombat(this);
var res = orig_getter.call(this);
res = (res && res._WB_wombat_obj_proxy) || res;
return res;
};
return obj_to_proxy(orig_getter.call(this));
}
def_prop(obj, prop, orig_setter, getter);
obj["_get_" + prop] = orig_getter;
}
@ -1906,7 +1902,7 @@ var _WBWombat = function($wbwindow, wbinfo) {
function receive_hash_change(event)
{
var source = event.source.__WBProxyRealObj__ || event.source;
var source = proxy_to_obj(event.source);
if (!event.data || source != $wbwindow.__WB_top_frame) {
return;
@ -2023,7 +2019,7 @@ var _WBWombat = function($wbwindow, wbinfo) {
source = win.__WB_win_id[event.data.src_id];
}
source = source.__WBProxyRealObj__ || source;
source = proxy_to_obj(source);
ne = new MessageEvent("message",
{"bubbles": event.bubbles,
@ -2132,7 +2128,7 @@ var _WBWombat = function($wbwindow, wbinfo) {
var orig_observe = $wbwindow.MutationObserver.prototype.observe;
function observe_deproxy(target, options) {
target = target && target.__WBProxyRealObj__ || target;
target = proxy_to_obj(target);
return orig_observe.call(this, target, options);
}
@ -2535,6 +2531,22 @@ var _WBWombat = function($wbwindow, wbinfo) {
// New Proxy Obj Override Functions
// Original Concept by John Berlin (https://github.com/N0taN3rd)
//============================================
function proxy_to_obj(source) {
try {
return source.__WBProxyRealObj__ || source;
} catch (e) {
return source;
}
}
function obj_to_proxy(obj) {
try {
return (obj && obj._WB_wombat_obj_proxy) || obj;
} catch (e) {
return obj;
}
}
function getAllOwnProps(obj) {
var ownProps = [];
@ -2568,7 +2580,7 @@ var _WBWombat = function($wbwindow, wbinfo) {
if (prop == '__WBProxyRealObj__') {
return obj;
} else if (prop == 'location') {
return obj._WB_wombat_location;
return obj._WB_wombat_location || (obj.defaultView && obj._WB_wombat_location);
} else if (prop == "_WB_wombat_obj_proxy") {
return obj._WB_wombat_obj_proxy;
}