Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 8801ef8

Browse files
jelbournkara
authored andcommitted
fix(tooltip): prevent xss in tooltip content (#10190)
1 parent 0b72ab9 commit 8801ef8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/components/tooltip/tooltip.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,
361361
if (!panelRef) {
362362
var id = 'tooltip-' + $mdUtil.nextUid();
363363
var attachTo = angular.element(document.body);
364-
var content = element.html().trim();
365364
var panelAnimation = $mdPanel.newPanelAnimation()
366365
.openFrom(parent)
367366
.closeTo(parent)
@@ -373,7 +372,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,
373372
var panelConfig = {
374373
id: id,
375374
attachTo: attachTo,
376-
template: content,
375+
contentElement: element,
377376
propagateContainerEvents: true,
378377
panelClass: 'md-tooltip ' + origin,
379378
animation: panelAnimation,

src/components/tooltip/tooltip.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ describe('MdTooltip Component', function() {
4949
expect(findTooltip()).toHaveClass('md-origin-bottom');
5050
});
5151

52+
it('should not re-templatize tooltip content', function() {
53+
$rootScope.name = '{{2 + 2}}';
54+
55+
buildTooltip(
56+
'<md-button>' +
57+
'<md-tooltip md-visible="true">{{name}}</md-tooltip>' +
58+
'</md-button>'
59+
);
60+
61+
expect(findTooltip().text()).toBe('{{2 + 2}}');
62+
});
63+
5264
it('should preserve parent text', function() {
5365
buildTooltip(
5466
'<md-button>' +

src/core/services/compiler/compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ MdCompilerService.prototype._fetchContentElement = function(options) {
296296
restoreFn = createRestoreFn(contentEl);
297297
} else {
298298
restoreFn = function() {
299-
contentEl.parentNode.removeChild(contentEl);
299+
if (contentEl.parentNode) {
300+
contentEl.parentNode.removeChild(contentEl);
301+
}
300302
}
301303
}
302304
}

0 commit comments

Comments
 (0)