-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Optionaly filter arguments of XSS-vulnerability-prone jqlite methods through $sce #12222
Comments
I am trying to understand what this issue is trying to address. If someone is able to run JavaScript in the context of an app, then any form of security measure is already gone. When would it be possible for someone to use |
The purpose of this feature is not to mitigate attacks (i.e. prevent an attacker from doing things once they already have script execution in the origin). Rather, it's to prevent developers from accidentally introducing vulnerabilities into the application in the first place. Some examples of bugs/vulnerabilities that can happen:
In all of these cases, the app works perfectly fine in dev, test, and normal, non-malicious usage; the strings in question usually don't contain any troublesome characters. IME it is very difficult for developers to always remember to apply correct sanitization and escaping when writing code that performs ad-hoc construction of HTML markup. Hence the desire to create APIs that are always safe (by default sanitize or escape their parameters, unless they are supplied in the form of types that promise that the values are already safe for a given context). For more background on this approach, see http://research.google.com/pubs/archive/42934.pdf. |
The main problem with changing the behavior of |
Would it be possible to provide a way to globally set the $sce to be used? On Sun, Jun 28, 2015 at 7:50 PM, Lucas Mirelmann [email protected]
|
Making jqLite use jQuery 1.12/2.2 introduced jQuery.htmlPrefilter through which the internal Would adding something like that to jqLite satisfy your needs, @xtofian? |
I'm not sure that would help a lot: the comments from last year are right in that jqLite lives outside of the Angular app. With something like this, we could hook the usual sanitizer / safe types combination, but since it has no reference to the Angular app, meshing its policies with the app's $sce would be brittle unless we duplicate infrastructure, which wouldn't be great either. Also, this htmlprefilter doesn't seem to provide any context, and it also doesn't hook attributes. We could certainly do some checks with it, but probably not in a really useable and complete way, so I'm not confident it's worth the effort. |
The JQuery API exposes several methods whose use in application code carries a high risk of introduction of XSS vulnerabilities.
For example, code such as
myElement.html(val)
results in XSS ifval
is (wholly or partially) derived from untrustworthy input, and not constructed in a way that ensures that sub-expressions have been appropriately sanitized and/or escaped for the context in which they appear in the HTML markup contained inval
. I.e., the use ofhtml(val)
carries a similar risk of XSS vulnerabilities as would be present due to the use ofng-bind-html
, if the latter did not address that risk by subjecting its argument expression to the$sanitize
and$sce
service.Hence it would be desirable to subject arguments to XSS-prone jqlite APIs (such as
.after(val)
,.before(html)
,.html(val)
, etc) to$sce
as well.Since this is a change that significantly changes behavior, it would need to be guarded by a configuration option.
Potential issues:
$sce
into jqlite?el.attr('title', val)
doesn't require any special sanitization or escaping onval
. However, inel.attr('href', url)
,url
needs to be sanitized as a safe URL.The text was updated successfully, but these errors were encountered: