mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Tooltip: Escape the title attribute so that it's treated as text and not HTML. Fixes #8861 - Tooltip: XSS vulnerability in default content.
This commit is contained in:
parent
5fee6fd500
commit
f2854408cc
@ -61,7 +61,7 @@
|
|||||||
// remove invalid value, as it didn't match anything
|
// remove invalid value, as it didn't match anything
|
||||||
$( element )
|
$( element )
|
||||||
.val( "" )
|
.val( "" )
|
||||||
.attr( "title", $( "<a>" ).text( value ).html() + " didn't match any item" )
|
.attr( "title", value + " didn't match any item" )
|
||||||
.tooltip( "open" );
|
.tooltip( "open" );
|
||||||
select.val( "" );
|
select.val( "" );
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
@ -16,6 +16,20 @@ test( "content: default", function() {
|
|||||||
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" );
|
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() {
|
test( "content: return string", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var element = $( "#tooltipped1" ).tooltip({
|
var element = $( "#tooltipped1" ).tooltip({
|
||||||
|
4
ui/jquery.ui.tooltip.js
vendored
4
ui/jquery.ui.tooltip.js
vendored
@ -46,7 +46,9 @@ $.widget( "ui.tooltip", {
|
|||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
options: {
|
options: {
|
||||||
content: function() {
|
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,
|
hide: true,
|
||||||
// Disabled elements have inconsistent behavior across browsers (#8661)
|
// Disabled elements have inconsistent behavior across browsers (#8661)
|
||||||
|
Loading…
Reference in New Issue
Block a user