Skip to content

Commit f285440

Browse files
committed
Tooltip: Escape the title attribute so that it's treated as text and not HTML. Fixes #8861 - Tooltip: XSS vulnerability in default content.
1 parent 5fee6fd commit f285440

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

demos/autocomplete/combobox.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
// remove invalid value, as it didn't match anything
6262
$( element )
6363
.val( "" )
64-
.attr( "title", $( "<a>" ).text( value ).html() + " didn't match any item" )
64+
.attr( "title", value + " didn't match any item" )
6565
.tooltip( "open" );
6666
select.val( "" );
6767
setTimeout(function() {

tests/unit/tooltip/tooltip_options.js

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ test( "content: default", function() {
1616
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" );
1717
});
1818

19+
test( "content: default; HTML escaping", function() {
20+
expect( 2 );
21+
var scriptText = "<script>$.ui.tooltip.hacked = true;</script>",
22+
element = $( "#tooltipped1" );
23+
24+
$.ui.tooltip.hacked = false;
25+
element.attr( "title", scriptText )
26+
.tooltip()
27+
.tooltip( "open" );
28+
equal( $.ui.tooltip.hacked, false, "script did not execute" );
29+
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText,
30+
"correct tooltip text" );
31+
});
32+
1933
test( "content: return string", function() {
2034
expect( 1 );
2135
var element = $( "#tooltipped1" ).tooltip({

ui/jquery.ui.tooltip.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ $.widget( "ui.tooltip", {
4646
version: "@VERSION",
4747
options: {
4848
content: function() {
49-
return $( this ).attr( "title" );
49+
var title = $( this ).attr( "title" );
50+
// Escape title, since we're going from an attribute to raw HTML
51+
return $( "<a>" ).text( title ).html();
5052
},
5153
hide: true,
5254
// Disabled elements have inconsistent behavior across browsers (#8661)

0 commit comments

Comments
 (0)