File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
ember-routing/lib/helpers Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff 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 ( ) {
Original file line number Diff line number Diff 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+ } ) ;
You can’t perform that action at this time.
0 commit comments