Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(tooltip): prevent xss in tooltip content (#10190)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored and kara committed Dec 29, 2016
1 parent 0b72ab9 commit 8801ef8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/components/tooltip/tooltip.js
Expand Up @@ -361,7 +361,6 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,
if (!panelRef) {
var id = 'tooltip-' + $mdUtil.nextUid();
var attachTo = angular.element(document.body);
var content = element.html().trim();
var panelAnimation = $mdPanel.newPanelAnimation()
.openFrom(parent)
.closeTo(parent)
Expand All @@ -373,7 +372,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,
var panelConfig = {
id: id,
attachTo: attachTo,
template: content,
contentElement: element,
propagateContainerEvents: true,
panelClass: 'md-tooltip ' + origin,
animation: panelAnimation,
Expand Down
12 changes: 12 additions & 0 deletions src/components/tooltip/tooltip.spec.js
Expand Up @@ -49,6 +49,18 @@ describe('MdTooltip Component', function() {
expect(findTooltip()).toHaveClass('md-origin-bottom');
});

it('should not re-templatize tooltip content', function() {
$rootScope.name = '{{2 + 2}}';

buildTooltip(
'<md-button>' +
'<md-tooltip md-visible="true">{{name}}</md-tooltip>' +
'</md-button>'
);

expect(findTooltip().text()).toBe('{{2 + 2}}');
});

it('should preserve parent text', function() {
buildTooltip(
'<md-button>' +
Expand Down
4 changes: 3 additions & 1 deletion src/core/services/compiler/compiler.js
Expand Up @@ -296,7 +296,9 @@ MdCompilerService.prototype._fetchContentElement = function(options) {
restoreFn = createRestoreFn(contentEl);
} else {
restoreFn = function() {
contentEl.parentNode.removeChild(contentEl);
if (contentEl.parentNode) {
contentEl.parentNode.removeChild(contentEl);
}
}
}
}
Expand Down

0 comments on commit 8801ef8

Please sign in to comment.