I have a translation key, which is actually HTML code, both encoded and unencoded.
$scope.translations = { "html_code" : "<script>alert('Alert!');</script>", "html_code_full" : "<script>alert('Alert!');</script>", "greeting" : "Welcome!" }
When I use these values ββto display translated text in the field of view, I use two methods:
- As a directive
<span translate>{{translations.html_code}}</span> - How to filter
{{translations.html_code|translate}}
I try the same for translations.html_code_full . Here is the code to view:
translations.html_code = {{translations.html_code|translate}} translations.html_code = <span translate>{{translations.html_code}}</span> translations.html_code_full = {{translations.html_code_full|translate}} translations.html_code_full = <span translate>{{translations.html_code_full}}</span>
This is the result I get:
translations.html_code = <script>alert('Alert!');</script> translations.html_code = <script>alert('Alert!');</script> translations.html_code_full = <script>alert('Alert!');</script> translations.html_code_full =
It is clear that the directory implementation encodes the translation key in HTML, but there is no filter. Why is this difference in the conclusion between the implementation of the directive and the filters? And why am I not getting a warning if it renders HTML?
Here is the panel I created for the demo.
angularjs xss angular-translate
Aniket sinha
source share