-
Notifications
You must be signed in to change notification settings - Fork 79
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
Assigning location.href
to a javascript:...
is a form of eval
#688
Comments
https://w3c.github.io/webappsec-csp/#directive-script-src seems pretty clear to me. And I doubt the corresponding algorithms would suggest anything different or be ambiguous in that manner. I also doubt this can be changed at this point. What browsers are inconsistent on this? Do you have a test? |
From the link above:
"Navigation to Whereas code that assigns However, item 4. ("JavaScript execution sinks") fails to include |
I agree it will be a challenge to fix things, but the current state of things it is very misleading to web developers. Most developers will assume that unless they include |
What do you mean is not a navigation? That's certainly a navigation. |
"3." Is talking about inline scripts that run automatically as the page is loaded. For code doing |
What makes you say that? Navigation there refers to the concept of navigation as defined in the HTML Standard. |
A But, back to the CSP spec, in step
"element" refers to the anchor in
Where another type of inline event handler is an anchor's Also elsewhere in the spec:
Code that dynamically assigns |
Do you agree that server-side and client-side attacks are two different classes of vulnerabilities? If so, it would follow that |
I don't really understand what you are trying to say. The HTML navigate algorithm calls out to CSP to handle |
Just wanted to point out that there are many other ways to dynamically execute scripts that aren't covered by CSP's The CSP spec is fairly clear that having |
I'm saying that "inline" is assumed to be content included in the HTML sent to the browser. The existence of these two directives suggests that someone initially intended for these to protect against server-side attacks vs client-side. Parts of the spec still seem to reflect this, while other parts make it look like the original intention got lost. |
While your assumption about the relative roles of For actual DOM XSS protection, Trusted Types are the mechanism that aims to guard all DOM code execution sinks and ensure that only objects with a special non-string type can be used in these sinks (and, in fact, they prevent the use of |
In Restriction 2: "Strings May Not Become Code" seems unambiguous to me. I think the issue was just that "... as are any equivalent functions" was not a complete inventory of the ways in which strings can become code. Also in Restriction 1:
Pretty clear the authors were specifically talking about If there's nothing that can be done at this point, fine. But from a historical perspective, it's clear that there were some gaps in the paper (and probably early versions of the spec), and that those gaps were filled over time in a way that lost the original intent. |
Extracted per request in the discussion in #322.
Assigning
location.href=
to a string that starts withjavascript:
is a form ofeval
, similar tosetTimeout(someString)
, and others. It should only execute ifunsafe-eval
is allowed. But currently in many browsersunsafe-inline
will allow this dynamically constructed JavaScript to be evaluated. This is likely due to ambiguity in the spec.What constitutes an "Inline" script is not well described in the spec. I think most would consider it to be scripts that appeared "in line" in the original HTML response. The reason such inline scripts might be unsafe is because a browser doesn't know if these scripts were dynamically constructed on the server, potentially using query params or other data an attacker would control (i.e. a reflection attack). When a page allows
unsafe-inline
, it's stating that such server-side attacks either don't apply, or have been considered and mitigated/sanitized on the backend.Both of the following are an example of inline script:
In both of the above, the script executed,
alert(0)
, was inline in the html returned from the server.By contrast, consider these:
All of these should be blocked unless
unsafe-eval
is allowed. The importance difference is that themalicious
script being executed is not inline. It may have been dynamically constructed in the browser, which is a much different threat than inline scripts originating from the server.The text was updated successfully, but these errors were encountered: