Skip to content

Commit

Permalink
Tooltip: Escape the title attribute so that it's treated as text and …
Browse files Browse the repository at this point in the history
…not HTML. Fixes #8861 - Tooltip: XSS vulnerability in default content.
  • Loading branch information
scottgonzalez committed Nov 27, 2012
1 parent 5fee6fd commit f285440
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demos/autocomplete/combobox.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
// remove invalid value, as it didn't match anything
$( element )
.val( "" )
.attr( "title", $( "<a>" ).text( value ).html() + " didn't match any item" )
.attr( "title", value + " didn't match any item" )
.tooltip( "open" );
select.val( "" );
setTimeout(function() {
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/tooltip/tooltip_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ test( "content: default", function() {
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" );
});

test( "content: default; HTML escaping", function() {
expect( 2 );
var scriptText = "<script>$.ui.tooltip.hacked = true;</script>",
element = $( "#tooltipped1" );

$.ui.tooltip.hacked = false;
element.attr( "title", scriptText )
.tooltip()
.tooltip( "open" );
equal( $.ui.tooltip.hacked, false, "script did not execute" );
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText,
"correct tooltip text" );
});

test( "content: return string", function() {
expect( 1 );
var element = $( "#tooltipped1" ).tooltip({
Expand Down
4 changes: 3 additions & 1 deletion ui/jquery.ui.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ $.widget( "ui.tooltip", {
version: "@VERSION",
options: {
content: function() {
return $( this ).attr( "title" );
var title = $( this ).attr( "title" );
// Escape title, since we're going from an attribute to raw HTML
return $( "<a>" ).text( title ).html();
},
hide: true,
// Disabled elements have inconsistent behavior across browsers (#8661)
Expand Down

0 comments on commit f285440

Please sign in to comment.