From afe20b79a64266e64011f34b26a30b3d1c62fd47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Wed, 12 May 2021 00:59:42 +0200 Subject: [PATCH] Datepicker: Make sure text option are text, shorten HTML strings Instead of using enormous HTML strings, various elements are now constructed using jQuery APIs. This makes it more obvious user-provided data is used correctly. Fixes #15284 Closes gh-1953 --- tests/unit/datepicker/options.js | 51 ++++++++++++ ui/widgets/datepicker.js | 136 ++++++++++++++++++++++++++----- 2 files changed, 166 insertions(+), 21 deletions(-) diff --git a/tests/unit/datepicker/options.js b/tests/unit/datepicker/options.js index e5e938a0f..e58b9a75d 100644 --- a/tests/unit/datepicker/options.js +++ b/tests/unit/datepicker/options.js @@ -1171,4 +1171,55 @@ QUnit.test( "Ticket 7602: Stop datepicker from appearing with beforeShow event h inp.datepicker( "destroy" ); } ); +QUnit.test( "Ticket #15284: escaping text parameters", function( assert ) { + assert.expect( 7 ); + + var done = assert.async(); + + var qf = $( "#qunit-fixture" ); + + window.uiGlobalXss = []; + + var inp = testHelper.init( "#inp", { + showButtonPanel: true, + showOn: "both", + prevText: "", + nextText: "", + currentText: "", + closeText: "", + buttonText: "", + appendText: "" + } ); + + var dp = $( "#ui-datepicker-div" ); + + testHelper.onFocus( inp, function() { + assert.equal( dp.find( ".ui-datepicker-prev" ).text().trim(), + "", + "prevText escaped" ); + assert.equal( dp.find( ".ui-datepicker-next" ).text().trim(), + "", + "nextText escaped" ); + assert.equal( dp.find( ".ui-datepicker-current" ).text().trim(), + "", + "currentText escaped" ); + assert.equal( dp.find( ".ui-datepicker-close" ).text().trim(), + "", + "closeText escaped" ); + + assert.equal( qf.find( ".ui-datepicker-trigger" ).text().trim(), + "", + "buttonText escaped" ); + assert.equal( qf.find( ".ui-datepicker-append" ).text().trim(), + "", + "appendText escaped" ); + + assert.deepEqual( window.uiGlobalXss, [], "No XSS" ); + + delete window.uiGlobalXss; + inp.datepicker( "hide" ).datepicker( "destroy" ); + done(); + } ); +} ); + } ); diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js index f03e075cd..4fd8843cf 100644 --- a/ui/widgets/datepicker.js +++ b/ui/widgets/datepicker.js @@ -240,7 +240,9 @@ $.extend( Datepicker.prototype, { inst.append.remove(); } if ( appendText ) { - inst.append = $( "" + appendText + "" ); + inst.append = $( "" ) + .addClass( this._appendClass ) + .text( appendText ); input[ isRTL ? "before" : "after" ]( inst.append ); } @@ -257,12 +259,32 @@ $.extend( Datepicker.prototype, { if ( showOn === "button" || showOn === "both" ) { // pop-up date picker when button clicked buttonText = this._get( inst, "buttonText" ); buttonImage = this._get( inst, "buttonImage" ); - inst.trigger = $( this._get( inst, "buttonImageOnly" ) ? - $( "" ).addClass( this._triggerClass ). - attr( { src: buttonImage, alt: buttonText, title: buttonText } ) : - $( "" ).addClass( this._triggerClass ). - html( !buttonImage ? buttonText : $( "" ).attr( - { src:buttonImage, alt:buttonText, title:buttonText } ) ) ); + + if ( this._get( inst, "buttonImageOnly" ) ) { + inst.trigger = $( "" ) + .addClass( this._triggerClass ) + .attr( { + src: buttonImage, + alt: buttonText, + title: buttonText + } ); + } else { + inst.trigger = $( "" : "" ); - - buttonPanel = ( showButtonPanel ) ? "
" + ( isRTL ? controls : "" ) + - ( this._isInRange( inst, gotoDate ) ? "" : "" ) + ( isRTL ? "" : controls ) + "
" : ""; + controls = ""; + if ( !inst.inline ) { + controls = $( "