-
Notifications
You must be signed in to change notification settings - Fork 78
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 |
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: