Skip to content

[WIP] Cross origin wrappers#16501

Closed
avadacatavra wants to merge 13 commits intoservo:masterfrom
avadacatavra:xow
Closed

[WIP] Cross origin wrappers#16501
avadacatavra wants to merge 13 commits intoservo:masterfrom
avadacatavra:xow

Conversation

@avadacatavra
Copy link
Copy Markdown
Contributor

@avadacatavra avadacatavra commented Apr 17, 2017

This PR adds some infrastructure required for XOWs.

Addresses #16243 and #2382


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/script_thread.rs, components/script/dom/window.rs, components/script/script_runtime.rs, components/script/dom/bindings/interface.rs, components/script/dom/bindings/utils.rs
  • @KiChjang: components/script/script_thread.rs, components/script/dom/window.rs, components/script/script_runtime.rs, components/script/dom/bindings/interface.rs, components/script/dom/bindings/utils.rs

@highfive
Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 17, 2017
@asajeffrey
Copy link
Copy Markdown
Contributor

Yay, security policy!

@cbrewster cbrewster removed their assignment Apr 17, 2017
bors-servo pushed a commit to servo/rust-mozjs that referenced this pull request Apr 18, 2017
added servojsprincipal skeleton

Cross origin wrappers (servo/servo#16501) require JSPrincipals. This PR adds the skeleton and basic functionality required.

CC: @jdm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/353)
<!-- Reviewable:end -->
@bors-servo
Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #16592) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Apr 24, 2017
@avadacatavra avadacatavra force-pushed the xow branch 2 times, most recently from c8ed375 to 39a524c Compare April 25, 2017 22:05

// avadacatavra: destroy will need to retrieved the boxed origin pointer, turn it back into a box and allow it to be freed
pub unsafe fn destroy_servo_jsprincipal(principal: &mut ServoJSPrincipal) {
let origin = GetPrincipalOrigin(principal.0) as *mut Box<MutableOrigin>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting to a *mut Box is incorrect; we need *mut MutableOrigin here so we can use from_raw and cause its destructor to run.

}
}

// avadacatavra: destroy will need to retrieved the boxed origin pointer, turn it back into a box and allow it to be freed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to remove this.

}

struct ServoJSPrincipal(*mut JSPrincipals);
//TODO make principal.rs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

match &*name {
"Location" => CrossOriginObjectType::CrossOriginLocation,
"Window" => CrossOriginObjectType::CrossOriginWindow,
_ => CrossOriginObjectType::CrossOriginOpaque,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let name = CStr::from_ptr((*obj_class).name).to_bytes();
match name {
    b"Location" => ...,
    b"Window" => ...,
    _ => ...,
}

}
}

unsafe fn target_subsumes_obj(cx: *mut JSContext, obj: HandleObject) -> bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this obj_subsumes_current_compartment.

values["members"] = "\n".join(members)

return CGGeneric("""\
let origin = object.origin().clone();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this clone if we pass a reference to create_global_object?

//TODO is same_origin_domain equivalent to subsumes for our purposes
pub unsafe extern fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals) -> bool {
let obj = &ServoJSPrincipal(obj);
let other = &ServoJSPrincipal(other);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The &s aren't necessary here.

//step 7 compare hosts

//step 8 compare ports
//false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are all covered by subsumes afaict, we don't need to leave references to them here.


unsafe fn select_wrapper(cx: *mut JSContext, obj: HandleObject) -> *const libc::c_void {
let security_wrapper = !target_subsumes_obj(cx, obj);
if !security_wrapper {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -387,7 +478,8 @@ unsafe extern "C" fn wrap(cx: *mut JSContext,
-> *mut JSObject {
// FIXME terrible idea. need security wrappers
// https://github.com/servo/servo/issues/2382
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments can go away.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 1, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels May 9, 2017
@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 9, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels May 12, 2017
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label May 12, 2017
@bors-servo
Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #16845) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label May 13, 2017
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 15, 2017
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label May 16, 2017
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 17, 2017
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label May 18, 2017
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 30, 2017
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label May 30, 2017
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 12, 2017
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Jun 12, 2017
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 15, 2017
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Jun 16, 2017
@jdm
Copy link
Copy Markdown
Member

jdm commented Nov 15, 2017

We're waiting to return to this work until we have a more recent spidermonkey.

@jdm jdm closed this Nov 15, 2017
@atouchet
Copy link
Copy Markdown
Contributor

@jdm @avadacatavra should this be re-opened now that SpiderMonkey has been updated?

@jdm
Copy link
Copy Markdown
Member

jdm commented Sep 10, 2018

No need to do that until someone is actually working on it.

yvt added a commit to yvt/servo that referenced this pull request Jul 13, 2021
bors-servo added a commit that referenced this pull request Jul 17, 2021
Implement `Location`'s custom internal methods

This PR partly resurrects #16501 and introduces the use of principals object to associate objects and Realms with origins. Using this infrastructure, this PR implements [the custom internal methods][1] of the `Location` interface, which is "maybe-cross-origin".

Other maybe-cross-origin interfaces, namely `WindowProxy` and `DissimilarWindowLocation`, aren't implemented correctly yet (causing most test cases of `tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html` to fail). [The "perform a security check" operation][2] and `Location`'s non-cross-origin properties' relevant `Document` origin checks aren't implemented either (not sure if they are covered by the existing tests). Finally, there are a slight deviation from the standard and inefficiency in `CrossOriginGetOwnPropertyHelper`'s current implementation.

[1]: https://html.spec.whatwg.org/multipage/#the-location-interface
[2]: https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #16243 and make some progress in #2382

---
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___
bors-servo added a commit that referenced this pull request Aug 1, 2021
Implement `Location`'s custom internal methods

This PR partly resurrects #16501 and introduces the use of principals object to associate objects and Realms with origins. Using this infrastructure, this PR implements [the custom internal methods][1] of the `Location` interface, which is "maybe-cross-origin".

Unimplemented/incomplete things:

 - Other maybe-cross-origin interfaces, namely `WindowProxy` and `DissimilarWindowLocation`, aren't implemented correctly yet (causing most test cases of `tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html` to fail).
     - `WindowProxy`: #28556
 - [The "perform a security check" operation][2] and `Location`'s non-cross-origin properties' relevant `Document` origin checks aren't implemented either (not sure if they are covered by the existing tests).
 - There are a slight deviation from the standard and inefficiency in `CrossOriginGetOwnPropertyHelper`'s current implementation.
     - #28557

[1]: https://html.spec.whatwg.org/multipage/#the-location-interface
[2]: https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #16243 and make some progress in #2382

---
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-needs-rebase There are merge conflict errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants