Intent to Deprecate and Remove: Stop evaluating scripts moved between Documents during fetching

80 views
Skip to first unread message

Hiroshige Hayashizaki

unread,
Sep 26, 2019, 11:24:44 PM9/26/19
to blink-dev, Domenic Denicola, Kouhei Ueno

Primary eng (and PM) emails

hiro...@chromium.org

kou...@chromium.org

dom...@chromium.org


Summary

Do not evaluate classic scripts, if <script> elements are moved between Documents during fetching.
Script elements can be still moved between Documents, but they won't be executed.


The current HTML spec (https://html.spec.whatwg.org) executes such scripts, but spec discussion is ongoing to stop executing such scripts:

https://github.com/whatwg/html/issues/2469

https://github.com/whatwg/html/pull/2673

https://github.com/web-platform-tests/wpt/pull/5911


Such scripts are already prevented from being evaluated on Firefox (all scripts) and Chromium (module scripts only).

This intent is to align the behavior of classic scripts on Chromium with Firefox.


Motivation

This is to prevent possible security bugs, because there have been several bad XSS-related bugs in Chromium due to the code path for executing <script> elements moved between Documents.

This will also simplify the spec and implementation of the current and future web platform features.


Interoperability and Compatibility Risk

Firefox: Already stops executing scripts moved between Documents.
Safari: No signal


See https://github.com/web-platform-tests/wpt/pull/5911#issuecomment-301188437 for a summary of current behaviors.


Alternative implementation suggestion for web developers

Instead of moving <script>s between documents, recreate them in the appropriate document. This will ensure they are fetched and evaluated in the expected context, i.e. that of the new document.


To re-create scripts, usual DOM APIs can be used, e.g.


const script = otherDocument.createElement('script');

script.textContent = originalScript.textContent;

otherDocument.body.append(script);


Usage information from UseCounter

Affects about <0.001% of page loads:

https://www.chromestatus.com/metrics/feature/timeline/popularity/2528 


Entry on the feature dashboard

https://www.chromestatus.com/feature/6025903192670208 


Requesting approval to remove too?

Yes (M-79).


Yoav Weiss

unread,
Sep 27, 2019, 12:31:55 AM9/27/19
to Hiroshige Hayashizaki, blink-dev, Domenic Denicola, Kouhei Ueno
On Fri, Sep 27, 2019 at 5:24 AM Hiroshige Hayashizaki <hiro...@chromium.org> wrote:

Primary eng (and PM) emails

hiro...@chromium.org

kou...@chromium.org

dom...@chromium.org


Summary

Do not evaluate classic scripts, if <script> elements are moved between Documents during fetching.
Script elements can be still moved between Documents, but they won't be executed.


The current HTML spec (https://html.spec.whatwg.org) executes such scripts, but spec discussion is ongoing to stop executing such scripts:

https://github.com/whatwg/html/issues/2469

https://github.com/whatwg/html/pull/2673

https://github.com/web-platform-tests/wpt/pull/5911


What's holding off that PR? What hasn't it landed?
 


Such scripts are already prevented from being evaluated on Firefox (all scripts) and Chromium (module scripts only).

This intent is to align the behavior of classic scripts on Chromium with Firefox.


Motivation

This is to prevent possible security bugs, because there have been several bad XSS-related bugs in Chromium due to the code path for executing <script> elements moved between Documents.

This will also simplify the spec and implementation of the current and future web platform features.


Interoperability and Compatibility Risk

Firefox: Already stops executing scripts moved between Documents.
Safari: No signal

Have we asked Safari/WebKit folks?
 


See https://github.com/web-platform-tests/wpt/pull/5911#issuecomment-301188437 for a summary of current behaviors.


Alternative implementation suggestion for web developers

Instead of moving <script>s between documents, recreate them in the appropriate document. This will ensure they are fetched and evaluated in the expected context, i.e. that of the new document.


To re-create scripts, usual DOM APIs can be used, e.g.


const script = otherDocument.createElement('script');

script.textContent = originalScript.textContent;

otherDocument.body.append(script);


Usage information from UseCounter

Affects about <0.001% of page loads:

https://www.chromestatus.com/metrics/feature/timeline/popularity/2528 


Entry on the feature dashboard

https://www.chromestatus.com/feature/6025903192670208 


Requesting approval to remove too?

Yes (M-79).


--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAOaYce72peyEH9xbKBTN7DUyi-ftb25uig-_w9BrmjVmi4A4VQ%40mail.gmail.com.

Domenic Denicola

unread,
Sep 27, 2019, 12:36:29 AM9/27/19
to Yoav Weiss, Hiroshige Hayashizaki, blink-dev, Domenic Denicola, Kouhei Ueno
> What's holding off that PR? What hasn't it landed?

We were waiting on the use counter data to see if Chrome (i.e. a second implementer) was interested. At this point we can merge the PR, although it will need to be rebased since it has been a while.

Also, I am going on vacation starting soon, so it may not land for two weeks for incidental reasons.

Yoav Weiss

unread,
Sep 27, 2019, 12:46:57 AM9/27/19
to Domenic Denicola, Hiroshige Hayashizaki, blink-dev, Domenic Denicola, Kouhei Ueno
OK, cool. Just wanted to make sure there are no substantial reasons for it. 

Alex Russell

unread,
Sep 30, 2019, 10:25:06 AM9/30/19
to blink-dev, d...@domenic.me, hiro...@chromium.org, dom...@chromium.org, kou...@chromium.org
LGTM1

TAMURA, Kent

unread,
Oct 3, 2019, 4:54:39 AM10/3/19
to Alex Russell, blink-dev, Domenic Denicola, hiro...@chromium.org, Domenic Denicola, Kouhei Ueno
LGTM2.

Firefox: Already stops executing scripts moved between Documents.

It's a good signal.


--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.


--
TAMURA Kent
Software Engineer, Google


Yoav Weiss

unread,
Oct 3, 2019, 4:57:29 AM10/3/19
to TAMURA, Kent, Alex Russell, blink-dev, Domenic Denicola, Hiroshige Hayashizaki, Domenic Denicola, Kouhei Ueno
LGTM3

Please open a WebKit bug to make sure this is on Safari's radar (pun not intended)

Hiroshige Hayashizaki

unread,
Oct 8, 2019, 8:35:25 PM10/8/19
to Yoav Weiss, TAMURA, Kent, Alex Russell, blink-dev, Domenic Denicola, Domenic Denicola, Kouhei Ueno
> Please open a WebKit bug to make sure this is on Safari's radar (pun not intended)
Reply all
Reply to author
Forward
0 new messages