Skip to content
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

Consider adding TT.emptyScript #218

Closed
koto opened this issue Sep 16, 2019 · 0 comments · Fixed by #251
Closed

Consider adding TT.emptyScript #218

koto opened this issue Sep 16, 2019 · 0 comments · Fixed by #251

Comments

@koto
Copy link
Member

koto commented Sep 16, 2019

This might be used to check for the eval(TrustedScript) support. It can't be polyfilled, and requires some support from the JavaScript runtime, so it's possible there would exist environments in which eval(TrustedScript) is not available, whereas other TT restrictions are supported. The check then might be:

if (eval(trustedTypes.emptyScript)) {
  // Traditionally, eval(nonString) returns its input, and Objects are truthy.
  eval("we_have_to_use_strings_here");
} else { 
  // eval(TrustedScript) would execute if supported, returning a falsy value.
  eval(myTrustedScriptObj)
}

or

eval(memoize(eval(trustedTypes.emptyString)) ? trustedScript.toString() : trustedScript)

That would allow authors to set up script-src 'unsafe-eval' 'trusted-script'; trusted-types a b c which would lock down eval() as much as it is possible for a given environment.

koto added a commit to koto/trusted-types that referenced this issue Dec 13, 2019
@koto koto closed this as completed in #251 Dec 13, 2019
koto added a commit that referenced this issue Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant