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