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

fix(tooltip): prevent xss in tooltip content #10190

Merged
merged 1 commit into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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