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

[WIP] Cross origin wrappers #16501

Closed
wants to merge 13 commits into from

frames override is the worst

  • Loading branch information
avadacatavra committed May 17, 2017
commit 0d9d5b33d537f99e2239240d8085e116fca72955
@@ -45,6 +45,12 @@ use std::ptr;
use std::slice;
use std::str;
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionBinding::DOMExceptionMethods;
use js::glue::SetIsFrameIdCallback;
use js::jsapi::jsid;
use js::jsapi::RootedId;
use js::rust::is_window;
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use dom::bindings::codegen::Bindings::DissimilarOriginWindowBinding::DissimilarOriginWindowBinding::DissimilarOriginWindowMethods;

/// Proxy handler for a WindowProxy.
pub struct WindowProxyHandler(pub *const libc::c_void);
@@ -91,14 +97,6 @@ unsafe fn identify_cross_origin_object(obj: HandleObject) -> CrossOriginObjectTy
let obj = UncheckedUnwrapObject(obj.get(), /* stopAtWindowProxy = */ 0);
let obj_class = JS_GetClass(obj);
let name = str::from_utf8(CStr::from_ptr((*obj_class).name).to_bytes()).unwrap().to_owned();
println!("{}, {:?}", name, obj);
//FIXME eeeek
if &*name == "DOMException" {
let mut ptr = JS_GetReservedSlot(obj, 0).to_private() as *mut DOMException;
let exception = &*ptr;
println!("DOMException: {:?}", exception.Message());
return CrossOriginObjectType::CrossOriginLocation;
}
match &*name {
"Location" => CrossOriginObjectType::CrossOriginLocation,
"Window" => CrossOriginObjectType::CrossOriginWindow,
@@ -152,16 +150,13 @@ pub unsafe extern fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals)
unsafe fn select_wrapper(cx: *mut JSContext, obj: HandleObject) -> *const libc::c_void {
let security_wrapper = !target_subsumes_obj(cx, obj);
if !security_wrapper {

This comment has been minimized.

Copy link
@jdm

jdm May 1, 2017

Member

This will be easier to reason about as if target_subsumes_obj(cx, obj) {.

println!("CCW");
return GetCrossCompartmentWrapper()
};

if identify_cross_origin_object(obj) != CrossOriginObjectType::CrossOriginOpaque {
println!("XOW");
return get_cross_origin_wrapper();
};

println!("opaque");
get_opaque_wrapper()
}

@@ -500,16 +495,37 @@ unsafe extern "C" fn wrap(cx: *mut JSContext,

unsafe extern "C" fn throw_dom_exception_callback(cx: *mut JSContext) {
//TODO it might not always be a SecurityError?
println!("throw dom exception callback");
throw_dom_exception(cx, &GlobalScope::from_context(cx), Error::Security);
}

unsafe extern "C" fn is_frame_id(cx: *mut JSContext, obj: *mut JSObject, id_arg: jsid) -> bool {
println!("is frame id");
/*if IsWrapper(obj) {
return false;
}
//let id = RootedId{_base: cx, ptr: idArg};
//will this work for window and dissimilaroriginwindow? probs not
if !is_window(obj) {
return false;
}
let win = obj as Window;
let col = win.Frames();
println!("{:?}", col);
//let clasp = get_object_class(obj);
//let name = str::from_utf8(CStr::from_ptr((*clasp).name).to_bytes()).unwrap().to_owned();
//println!("{:?}", name);*/
false
}

unsafe extern "C" fn pre_wrap(cx: *mut JSContext,
_existing: HandleObject,
obj: HandleObject,
_object_passed_to_wrap: HandleObject)
-> *mut JSObject {
SetThrowDOMExceptionCallback(Some(throw_dom_exception_callback));
SetIsFrameIdCallback(Some(is_frame_id));
let _ac = JSAutoCompartment::new(cx, obj.get());
let obj = ToWindowProxyIfWindow(obj.get());
assert!(!obj.is_null());
@@ -84,7 +84,7 @@ impl DissimilarOriginWindowMethods for DissimilarOriginWindow {

// https://html.spec.whatwg.org/multipage/#dom-frames
fn Frames(&self) -> Root<BrowsingContext> {
println!("calling frames");
println!("calling cross origin frames");
Root::from_ref(&*self.browsing_context)
}

@@ -57,30 +57,14 @@
assert_equals(location.hostname, host_info.ORIGINAL_HOST, 'Need to run the top-level test from domain ' + host_info.ORIGINAL_HOST);
assert_equals(get_port(location), host_info.HTTP_PORT, 'Need to run the top-level test from port ' + host_info.HTTP_PORT);
assert_equals(B.parent, window, "window.parent works same-origin");
//assert_equals(C.parent, window, "window.parent works cross-origin");
assert_equals(C.parent, window, "window.parent works cross-origin");
assert_equals(B.location.pathname, path, "location.href works same-origin");
//TODO do document.write and console.log have same behavior?
try {
console.log("C.location.pathname should throw");
console.log(C.location.pathname); //permission denied to unwrap object
} catch(err) {
console.log(err); //ok it's getting that it's a security error, but not reading it right for the asssert
}
//console.log(C.location.pathname);
//assert_throws("SecurityError", function() { C.location.pathname; }, "location.pathname throws cross-origin");
try {
console.log("B.frames: override");
console.log(B.frames);
} catch(err) {
console.log(err);
}
assert_throws("SecurityError", function() { C.location.pathname; }, "location.pathname throws cross-origin");
assert_equals(B.frames, 'override', "Overrides visible in the same-origin case");
try {
console.log("C.frames should throw");
console.log(C.frames);
} catch(err) {
console.log(err);
}
console.log("C.frames");
console.log(C.frames);
//assert_equals(C.frames, C, "Overrides invisible in the cross-origin case");
}, "Basic sanity-checking");

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.