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

Wire up 'HostEnsureCanCompileStrings' to CSP #1005

Closed
wants to merge 5 commits into from
Closed

Wire up 'HostEnsureCanCompileStrings' to CSP #1005

wants to merge 5 commits into from

Conversation

mikewest
Copy link
Member

@mikewest mikewest commented Apr 6, 2016

CSP defines an implementation of 'HostEnsureCanCompileStrings' which throws an
'EvalError' if string compilation is disallowed. This patch wires that implementation
up to the 'HostEnsureCanCompileStrings' abstract operation.

#271

@mikewest
Copy link
Member Author

mikewest commented Apr 6, 2016

@domenic, @annevk: PTAL. I didn't follow Domenic's suggestions exactly, as this patch explicitly delegates to an operation defined in CSP rather than delegating the definition to CSP. I've done that because it's possible that something like https://wicg.github.io/ContentPerformancePolicy/ will also want to take a crack at limiting eval(), so I'd suggest that keeping the definition in HTML makes sense.

If you'd prefer to resolve this differently (e.g. delegate entirely to CSP until some other spec comes along), I'm happy to defer to y'all on that.

data-x="js-HostEnsureCanCompileStrings">HostEnsureCanCompileStrings</span>(<var>callerRealm</var>,
<var>calleeRealm</var>) abstract operation <ref spec=JAVASCRIPT>. User agents must use the <span
data-x="csp-EnsureCSPDoesNotBlockStringCompilation">EnsureCSPDoesNotBlockStringCompilation(<var>callerRealm</var>,
<var>calleeRealm</var>)</span> implementation defined in <ref spec=CSP>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <ref>s should be after the final dot, before </p>. Your approach seems okay to me.

@domenic
Copy link
Member

domenic commented Apr 6, 2016

This approach does seem nice to me; I like that it makes HTML responsible for defining all the HostWhatever operations in one place. Let me get to work and compile and view the output before giving final LGTM on editorial issues.

@mikewest
Copy link
Member Author

mikewest commented Apr 6, 2016

Addressed nits. Happy to make more changes once you take a closer look. :)

@@ -86244,9 +86244,10 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {

<p>JavaScript contains an implementation-defined <span
data-x="js-HostEnsureCanCompileStrings">HostEnsureCanCompileStrings</span>(<var>callerRealm</var>,
<var>calleeRealm</var>) abstract operation <ref spec=JAVASCRIPT>. User agents must use the <span
<var>calleeRealm</var>) abstract operation . User agents must use the <span
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to remove the space before the dot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Fixed. :)

@domenic
Copy link
Member

domenic commented Apr 6, 2016

OK, so, a bit of work to do still I think. I think we want to follow the pattern previously established, which means you say:

User agents must use the following implementation: [JAVASCRIPT]

  1. Perform ? EnsureCSPDoesNotBlockStringCompilation(callerRealm, calleeRealm). [CSP]

Also, either you or I can do this, but we need to actually patch setTimeout and setInterval too to call this. I guess maybe we should wait for #951 to land to avoid conflicts though.

mikewest and others added 4 commits April 7, 2016 07:34
CSP defines an implementation of 'HostEnsureCanCompileStrings' which throws an
'EvalError' if string compilation is disallowed. This patch wires that implementation
up to the 'HostEnsureCanCompileStrings' abstract operation.

#271
@annevk
Copy link
Member

annevk commented Apr 7, 2016

Should event handlers call this too?

@mikewest
Copy link
Member Author

mikewest commented Apr 7, 2016

I think we want to follow the pattern previously established

Done.

we need to actually patch setTimeout and setInterval too

I took a stab at this. WDYT?

Should event handlers call this too?

No. Event handler attributes are "inline" JavaScript vs. dynamically compiled script.

@annevk
Copy link
Member

annevk commented Apr 7, 2016

@mikewest hmm, setAttribute("onclick", "...") is not dynamically compiled?

@mikewest
Copy link
Member Author

mikewest commented Apr 7, 2016

hmm, setAttribute("onclick", "...") is not dynamically compiled?

Huh. I guess it is. It's not clear to me that there's much value in gating it on both 'unsafe-inline' and 'unsafe-eval' though (since if the former is present, the code could just be injected directly via innerHTML and the like.

Still, it might be more internally consistent to treat setAttribute the same as setTimeout if it's setting a handler. I don't think the spec currently distinguishes between the two, and it's not clear whether you'd want me to handle that in DOM (with setAttribute) or in HTML (in "get the current value of the event handler", I suppose?). WDYT?

@Ms2ger
Copy link
Member

Ms2ger commented Apr 7, 2016

I think in HTML would make the most sense.

@annevk
Copy link
Member

annevk commented Apr 7, 2016

I think I agree with @Ms2ger. It would mean setAttribute() would not throw and the value would be set as-is, but it would not work either since it never got compiled. So far setAttribute() has remained clean from any special cases and it seems nice to preserve that.

@mikewest
Copy link
Member Author

mikewest commented Apr 7, 2016

Ok. Wherever we do the setAttribute check (and I've come around to the idea that it's a good thing to do), would you mind if we did it in a separate patch? This patch is basically behavior that exists. The next patch would be behavior that doesn't exist. I think it would be helpful to label the patch as a change, and to tie it to a relevant change in the CSP spec.

Filed w3c/webappsec-csp#67 to cover those changes.

@annevk
Copy link
Member

annevk commented Apr 7, 2016

That sounds fine to me. I'll let @domenic land this though and do a final review.

@shekyan
Copy link

shekyan commented Apr 7, 2016

Shouldn't this cover cloneNode ?

@domenic
Copy link
Member

domenic commented Apr 8, 2016

Going to leave a couple comments, but I'll fix up and merge myself since you did all the hard work and I haven't been a super-responsive reviewer so I don't want to put you through more days of back and forth.

<ol>

<li><p>Perform ? <span
data-x="csp-EnsureCSPDoesNotBlockStringCompilation">EnsureCSPDoesNotBlockStringCompilation(<var>callerRealm</var>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

span should wrap the function name, not the function call

@domenic
Copy link
Member

domenic commented Apr 8, 2016

Merged as 374b54d; forgot the "PR: ..." line sadly.

@domenic domenic closed this Apr 8, 2016
@domenic domenic added the addition/proposal New features or enhancements label Apr 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements
Development

Successfully merging this pull request may close these issues.

5 participants