Optionaly filter arguments of XSS-vulnerability-prone jqlite methods through $sce #12222
Description
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 if val
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 in val
. I.e., the use of html(val)
carries a similar risk of XSS vulnerabilities as would be present due to the use of ng-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:
- How to inject
$sce
into jqlite? - Some methods require sanitization that is data depedent. For example,
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.