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

fix(tooltip): properly interpolate tooltip text to prevent possible XSS #10159

Merged
merged 1 commit into from
Dec 21, 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
5 changes: 3 additions & 2 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,

function addAriaLabel(override) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jelbourn - Per the PR ancestor (that was closed), we should add comments about what is override ?

if (override || !parent.attr('aria-label')) {
var rawText = override || element.text().trim();
var interpolatedText = $interpolate(rawText)(parent.scope());
// Only interpolate the text from the HTML element because otherwise the custom text
// could be interpolated twice and cause XSS violations.
var interpolatedText = override || $interpolate(element.text().trim())(parent.scope);
parent.attr('aria-label', interpolatedText);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/components/tooltip/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ describe('MdTooltip Component', function() {

expect(element.attr('aria-label')).toBe('test 2');
});

it('should not interpolate interpolated values', function() {
buildTooltip(
'<md-button>' +
'<md-tooltip>{{ testModel.ariaTest }}</md-tooltip>' +
'</md-button>'
);

$rootScope.$apply(function() {
$rootScope.testModel.ariaTest = 'test {{1+1}}';
});

expect(element.attr('aria-label')).toBe('test {{1+1}}');

$rootScope.$apply(function() {
$rootScope.testModel.ariaTest = 'test {{1+1336}}';
});

expect(element.attr('aria-label')).toBe('test {{1+1336}}');
});

it('should not set parent to items with no pointer events',
inject(function($window) {
Expand Down