-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[js-interop] Type/null check causes error on sandboxed iframe window access #54443
Comments
Perhaps it's such a niche case we could just document it as a limitation or have some sort of helper in I've ended up implementing a simple extension to implement it to avoid the checks causing the error: extension on HTMLIFrameElement {
void safelyPostMessage(
JSAny? message,
String optionsOrTargetOrigin,
) {
(this as JSObject)
.getProperty<JSObject>('contentWindow'.toJS)
.callMethod('postMessage'.toJS, message, optionsOrTargetOrigin.toJS);
}
} Maybe I could simplify this further too? Happy to try out other ideas if you have them :D |
We came across something similar here when we modified This is kind of a tough one to solve, and will require a bit more thought on my end. Possible solutions:
|
Thanks for the details and response. It does seem a bit tough to solve, while also being limited in scope, so I'm not too worried about it yet as long as we can document it.
Is this an issue for any other type besides the iframe window use case? If not, 2 and 3 seem likely not worth the implementation effort or potential size/perf impact. Perhaps we can document this clearly, see how JS-interop and |
It should only affect cross-frame objects. Helpers are a good workaround and there is precedent in To be fair, the weirdness of cross-frame objects doesn't stop here. And of course, suggestion 3 can only work when we know the static type, but I don't expect users to use For now, documentation is reasonable either in |
Adding docs seems like a great start. I worry (2) may not be feasible because it needs to be a property that all foreign cross-iframe object allow. Window allows Another idea similar to (3) could be to add a special type for cross-iframe objects (e.g. add |
Extension types are erased early in dart2js, so this may require caching information to emit the right null-checks. My proposal in 3 wasn't clear, but I was thinking more when the static type (post-erasure) is |
FWIW, my subsequent idea was also to make this distinction post erasure (adding an interceptors.JSCrossFrameObject that is a subtype of interceptors.JSObject) |
Got it, that'll work too. |
Adding a message here to remind myself to put this in the docs. |
Closes dart-lang/sdk#54443 Closes dart-lang#247 Closes dart-lang/sdk#54938 Since cross-origin objects have limitations around access, wrappers are introduced to do the only safe operations. Extension methods are added to get instances of these wrappers.
Trying to access the
contentWindow
of a sandboxed iframe results in an error similar to the following:I don't know enough about the web compilers or JS-interop to understand the source of the problem, but I'm assuming the
.toString
is added as a null check (in the case of optimizeddart2js
)? Whether that's why or not, it seems most property access outside ofpostMessage
is disallowed for cross-origin frames. If I remove thetoString
from the generated JS, a followingpostMessage
works fine.I know the goal is for the new JS-interop to have less special handling by the compilers. However, to be compatible with the browser's security mechanism here, maybe a tiny bit of a special handling somewhere would be helpful?
Minimal reproduction:
The text was updated successfully, but these errors were encountered: