This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(autocomplete): pulls in text content as HTML to prevent it from b…
…eing un-escaped
- Loading branch information
33ac259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the test 😛
(Seriously, I think there should be a test guarding against regressions here.)
BTW, I believe there are cases where things can break (not XSS vulnerability, but unexpected/incorrect handling), when
$element
contains other element nodes.E.g.:
(A proper solution might be non-trivial though.)
33ac259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkalpak Right, the intent of
md-highlight-text
is to ONLY contain text. I think proper handling of this would be to warn the user if they mis-use it. The idea is that your example should look like this:33ac259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robertmesserle, this makes perfect sense, in which case I would suggest:
Document it (so people don't get their templates unexpectedly broken).
Make sure the element only contains text before starting to interpolate etc; e.g. with something like:
WDYT ?
33ac259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, @robertmesserle, this does not fix the problem (I am afraid I kind of mislead you; I seem to be doing this a lot to people lately).
The problem could be caused by an effective
$element.html($element.text())
, but it's not :DThe real problem comes from
text = $interpolate($element.whatever())($scope),
. Basically, since$element
most probably contains some interpolated text,text
comes from some property's value on$scope
. Thus, it has not passed through any "filtering" (either by Angular or the browser itself) and can be anything (including<script>...
).So, by using
$element.html(text)
, you are "light-heartedly" putting an arbitrary string from$scope
directly as the element's HTML. So, you should first make the originaltext
safe (i.e. encode HTML entities) and then insert<span class="md-highlight">...</span>
and pass it to$element.html()
.A quick fix that comes into mind would be:
(I wouldn't be surprised if there was a better solution though 😉)
33ac259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robertmesserle, POC that the proposed fix above fixes the issue: http://codepen.io/ExpertSystem/pen/KpMLYv?editors=001
(If you remove the overwriting
MdHighlightCtrl
, you'll noticed we get pwned.)