You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Opening a window with a different origin using JS interop (using JSAny? to avoid any type checks) and then trying to access a property that is invalid e.g. devicePixelRatio succeeds.
Running the following with dart test test/helpers_test.dart -p chrome:
@TestOn('browser')
library;
import'dart:js_interop';
import'package:test/test.dart';
@JS()
externalJSAny?get window;
voidmain() {
test('test', () {
final w = window.open('https://www.google.com');
if (w ==null) throwException();
w.devicePixelRatio;
});
}
extensiononJSAny? {
externalJSAny?open(String url);
externalint devicePixelRatio;
}
However, if I add --pause-after-load and add a breakpoint to if (w == null) and then run w.devicePixelRatio in the console, this correctly results in a SecurityError. Similarly, if I single-step, it correctly throws the error.
I can't quite tell why this is the case. It doesn't look like package:test uses any of the headers to allow such access. It could also be that we need to actually enable same-origin policy for this (I know it's not enabled for script tags, but maybe it's not enabled for other relevant scenarios by default) and single-stepping/console execution always respects same-origin policy. The tests being run in an iframe also shouldn't allow this afaict.
This came up when trying to add some wrappers in package:web to allow cross-origin access to approved properties: dart-lang/web#291. While the test in that PR passes, I can't tell if it's really doing the right thing or we're just silently ignoring any SecurityErrors because of this bug. I had to single-step to verify.
Fixing this might make a few tests across the ecosystem fail due to new SecurityErrors.
The text was updated successfully, but these errors were encountered:
Opening a window with a different origin using JS interop (using
JSAny?
to avoid any type checks) and then trying to access a property that is invalid e.g.devicePixelRatio
succeeds.Running the following with
dart test test/helpers_test.dart -p chrome
:The resulting JS looks like:
However, if I add
--pause-after-load
and add a breakpoint toif (w == null)
and then runw.devicePixelRatio
in the console, this correctly results in aSecurityError
. Similarly, if I single-step, it correctly throws the error.I can't quite tell why this is the case. It doesn't look like
package:test
uses any of the headers to allow such access. It could also be that we need to actually enable same-origin policy for this (I know it's not enabled forscript
tags, but maybe it's not enabled for other relevant scenarios by default) and single-stepping/console execution always respects same-origin policy. The tests being run in an iframe also shouldn't allow this afaict.This came up when trying to add some wrappers in
package:web
to allow cross-origin access to approved properties: dart-lang/web#291. While the test in that PR passes, I can't tell if it's really doing the right thing or we're just silently ignoring anySecurityError
s because of this bug. I had to single-step to verify.Fixing this might make a few tests across the ecosystem fail due to new
SecurityError
s.The text was updated successfully, but these errors were encountered: