angular-translate / angular-translate

DEPRECATED Translating your AngularJS 1.x apps
https://angular-translate.github.io
MIT License
4.33k stars 1.04k forks source link

$translate.instant with angular expression #1915

Open fjh352 opened 2 years ago

fjh352 commented 2 years ago

Subject of the issue

Describe your issue here. $translate.instant with angular expression, such like: {{constructor.constructor('alert(JSON.stringify(localStorage))')()}} lt will pop alart after run this logic

Your environment

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working demo, you can use this template as a base.

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

knalli commented 2 years ago

Yes, the same as having this in your app's template:

<span>{{constructor.constructor('alert(JSON.stringify(localStorage))')()}}</span>

angular-translate relies on the same technique under the hood when interpolating your variables. The translation keys are meant to be string keys and in your control. Both template and translation keys should be under your (and your app's) control.

In security aspects, that is not ideal. But the official long term support of AngularJS has also stopped at the beginning of this year.

If you think there is a reasonable fix for this without breaking everything, you are welcome making a PR.