-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
translate-params-* allows usage of HTML content under certain conditions (potential security issue) #348
Comments
FYI, here is a fiddle demonstrating the attack using an injected JavaScript alert(): Again: obviously the javascript code should have never made it to the database, but it COULD have made it to the database, therefor this poses a security risk! |
As a potential way to fix:
$compile(newWrapper.contents())(interpolationContext || scope); This fixes the XSS problem in the first place, but I'm not sure if it creates new problems. |
…onContext is now a real subscope
…ng/getPlural to avoid which is not XSS safe
…onContext is now a real subscope
…onContext is now a real subscope
Hi – I'm one of the developers who'd like to retain the ability to inject HTML. In our use case we write icons into the string as variables for example, or links. Fixing it via $sce is possible but not very nice – are there plans for a HTML attribute which would allow this? |
Hi! I actually had the same use-case (and that was the way I found this vulnerability too). I have added a <div translate translate-html-params-my-icon="myIcon">
I have a nice icon {{ myIcon }}
</div> $scope.myIcon = "<span class=\"fa fa-some-icon\"></span>"; If people are interested, I can make a Pull Request with documentation and tests into this repo. |
I'm no fan of unneeded features, but this one definitely serves a purpose. Would gladly accept a PR! |
@anx-ckreuzberger count me in as interested ;-) Do you have a fork with that feature? |
Yes I do. my package.json contains this: "angular-gettext": "git+https://github.com/anx-ckreuzberger/angular-gettext#htmlparams2", |
@rubenv do you think there would be more work to be done in order to merge a pull request with this diff? |
Hi all, sorry for the late reply. I've been travelling and well... I don't have the needed time anymore. For that reason, please have a look at #365. |
…onContext is now a real subscope
…erpolationContext is now a real subscope" This reverts commit 4b08e12.
The Issue
Assuming this is your controller:
And this is your HTML
AngularJS and/or angular-gettext will make sure, that
someUnsafeHtml
is properly escaped. So far, so good.However, as soon as you use the
translate-params-some-unsafe-html="someUnsafeHtml"
attribute,someUnsafeHtml
is no longer escaped.Interesting enough, the string also seems to be not escaped, when using a different attribute name and empty value (
translate-params-nothing
):I believe that this behaviour is not the intended behaviour, as this means that there is a potential security issue as soon as one uses the
translate-params-
attributes is used with user generated content (of course, one should always sanitize input variables before adding them to the database).I have created a jsfiddle with Angular 1.5.10 and angular-gettext 2.3.10 that displays some other cases aswell: https://jsfiddle.net/wy0fu3hd/9/
I believe that it should be possible to render HTML, if and only if you specifically mark the content as trusted HTML content using
$sce
and specially use the
translate-params-
attributeThough it might make sense that this is only supported using some additional attribute, e.g.:
Also paging @IShotTheSheriff on this, as the original concept is from him (issue #285).
Analysis
This is happening because of the
getString
method ingettextCatalog
(see https://github.com/rubenv/angular-gettext/blob/master/src/catalog.js#L243-L249):Especially the part where it says
$interpolate(string)(scope)
.The
$interpolate
factory/service is called when a scope is passed to the getString function. This happens when using thetranslate-params-*
attribute, as this defines aninterpolationContext
:Here
var interpolationContext = angular.extend({}, scope);
creates a new scope, which is then getting the values of the passed parameters oftranslate-params-*
:interpolationContext[key] = newVal;
Then the
update(interpolationContext)
method is called, which calls thegetString()
method from above with theinterpolationContext
asscope
.By calling
$interpolate
here, we will end up with an interpolated string, which is eventually set as the main content of the element in theupdate()
method:Solution
I am not sure, how to solve this problem yet. Surely it has something to do with the combination of $interpolate and $compile aswell as the concatenation
'<span>' + translated + '</span>'
.I am however sure, that it should be possible to inject HTML, if specified by the developer.
The text was updated successfully, but these errors were encountered: