Skip to content

Commit ab3199e

Browse files
committed
[SECURITY CVE-2014-0046] Ensure link-to non-block escapes title.
Conflicts: packages/ember-routing/lib/helpers/link_to.js packages/ember/tests/helpers/link_to_test.js
1 parent 92fcdfe commit ab3199e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/ember-routing/lib/helpers/link_to.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,16 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
732732
if (linkType === 'ID') {
733733
options.linkTextPath = linkTitle;
734734
options.fn = function() {
735-
return Ember.Handlebars.get(context, linkTitle, options);
735+
var result = Ember.Handlebars.get(context, linkTitle, options);
736+
if (result === null || result === undefined) {
737+
result = "";
738+
} else if (!(result instanceof Handlebars.SafeString)) {
739+
result = String(result);
740+
}
741+
if (!options.hash.unescaped){
742+
result = Handlebars.Utils.escapeExpression(result);
743+
}
744+
return result;
736745
};
737746
} else {
738747
options.fn = function() {

packages/ember/tests/helpers/link_to_test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,3 +1140,25 @@ if (Ember.FEATURES.isEnabled('link-to-non-block')) {
11401140
assertEquality('/about');
11411141
});
11421142
}
1143+
1144+
test("The non-block form {{link-to}} protects against XSS", function() {
1145+
Ember.TEMPLATES.application = Ember.Handlebars.compile("{{link-to display 'index' id='link'}}");
1146+
1147+
App.ApplicationController = Ember.Controller.extend({
1148+
display: 'blahzorz'
1149+
});
1150+
1151+
bootApplication();
1152+
1153+
Ember.run(router, 'handleURL', '/');
1154+
1155+
var controller = container.lookup('controller:application');
1156+
1157+
equal(Ember.$('#link', '#qunit-fixture').text(), 'blahzorz');
1158+
Ember.run(function() {
1159+
controller.set('display', '<b>BLAMMO</b>');
1160+
});
1161+
1162+
equal(Ember.$('#link', '#qunit-fixture').text(), '<b>BLAMMO</b>');
1163+
equal(Ember.$('b', '#qunit-fixture').length, 0);
1164+
});

0 commit comments

Comments
 (0)