Open
Description
I think HTMLScriptElement
needs a src setter that accepts a TrustedScriptURL
.
After conditionally creating a trustedUrl like this:
// If TrustedTypes are available, prepare a trusted URL.
web.TrustedScriptURL? trustedUrl;
if ((web.window as JSObject).hasProperty('trustedTypes'.toJS).toDart) {
// create a TrustedTypePolicy `policy` object
trustedUrl = policy.createScriptURL(_url, null);
}
I'm finding myself doing this:
final web.HTMLScriptElement script =
// ignore: avoid_dynamic_calls
(web.document.createElement('script') as dynamic
// ignore: unsafe_html
..src = (trustedUrl ?? _url)
..async = true
..defer = true) as web.HTMLScriptElement;
Docs:
- https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API
- See "Injection Sinks": Setters for Element attributes that accept a URL of code to load or execute.
- https://developer.mozilla.org/en-US/docs/Web/API/TrustedScriptURL
(Another way would be to pass trustedUrl.toString()
, but that kind of defeats the purpose of TrustedScriptURLs, and would still flag me as unsafe_html
I think :/)
Metadata
Metadata
Assignees
Labels
No labels