mirror of
https://github.com/apache/superset.git
synced 2026-06-16 21:19:18 +00:00
Compare commits
1 Commits
bump-setup
...
fix/nvd3-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4debd2d01a |
@@ -162,7 +162,7 @@ export function generateMultiLineTooltipContent(d, xFormatter, yFormatters) {
|
|||||||
|
|
||||||
tooltip += '</tbody></table>';
|
tooltip += '</tbody></table>';
|
||||||
|
|
||||||
return tooltip;
|
return dompurify.sanitize(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateTimePivotTooltip(d, xFormatter, yFormatter) {
|
export function generateTimePivotTooltip(d, xFormatter, yFormatter) {
|
||||||
@@ -223,7 +223,7 @@ export function generateBubbleTooltipContent({
|
|||||||
s += createHTMLRow(getLabel(sizeField), sizeFormatter(point.size));
|
s += createHTMLRow(getLabel(sizeField), sizeFormatter(point.size));
|
||||||
s += '</table>';
|
s += '</table>';
|
||||||
|
|
||||||
return s;
|
return dompurify.sanitize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// shouldRemove indicates whether the nvtooltips should be removed from the DOM
|
// shouldRemove indicates whether the nvtooltips should be removed from the DOM
|
||||||
@@ -287,9 +287,11 @@ export function tipFactory(layer) {
|
|||||||
? layer.descriptionColumns.map(c => d[c])
|
? layer.descriptionColumns.map(c => d[c])
|
||||||
: Object.values(d);
|
: Object.values(d);
|
||||||
|
|
||||||
return `<div><strong>${title}</strong></div><br/><div>${body.join(
|
return dompurify.sanitize(
|
||||||
', ',
|
`<div><strong>${title}</strong></div><br/><div>${body.join(
|
||||||
)}</div>`;
|
', ',
|
||||||
|
)}</div>`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import {
|
|||||||
computeYDomain,
|
computeYDomain,
|
||||||
getTimeOrNumberFormatter,
|
getTimeOrNumberFormatter,
|
||||||
formatLabel,
|
formatLabel,
|
||||||
|
generateBubbleTooltipContent,
|
||||||
|
generateMultiLineTooltipContent,
|
||||||
|
tipFactory,
|
||||||
} from '../src/utils';
|
} from '../src/utils';
|
||||||
|
|
||||||
const DATA = [
|
const DATA = [
|
||||||
@@ -181,4 +184,61 @@ describe('nvd3/utils', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('tooltip HTML sanitization', () => {
|
||||||
|
const identity = (v: unknown) => v;
|
||||||
|
|
||||||
|
test('generateBubbleTooltipContent strips scripts from entity/group', () => {
|
||||||
|
const html = generateBubbleTooltipContent({
|
||||||
|
point: {
|
||||||
|
name: '<img src=x onerror="alert(1)">',
|
||||||
|
group: '<script>alert(2)</script>',
|
||||||
|
color: 'red',
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
size: 3,
|
||||||
|
},
|
||||||
|
entity: 'name',
|
||||||
|
xField: 'x',
|
||||||
|
yField: 'y',
|
||||||
|
sizeField: 'size',
|
||||||
|
xFormatter: identity,
|
||||||
|
yFormatter: identity,
|
||||||
|
sizeFormatter: identity,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(html).not.toContain('onerror');
|
||||||
|
expect(html).not.toContain('<script>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('generateMultiLineTooltipContent strips scripts from series keys', () => {
|
||||||
|
const html = generateMultiLineTooltipContent(
|
||||||
|
{
|
||||||
|
value: 'x',
|
||||||
|
series: [
|
||||||
|
{ key: '<img src=x onerror="alert(1)">', color: 'red', value: 1 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
identity,
|
||||||
|
[identity],
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(html).not.toContain('onerror');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('tipFactory strips scripts from annotation data values', () => {
|
||||||
|
const tip = tipFactory({
|
||||||
|
titleColumn: 'title',
|
||||||
|
name: 'layer',
|
||||||
|
descriptionColumns: ['desc'],
|
||||||
|
});
|
||||||
|
const html = tip.html()({
|
||||||
|
title: '<img src=x onerror="alert(1)">',
|
||||||
|
desc: '<script>alert(2)</script>',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(html).not.toContain('onerror');
|
||||||
|
expect(html).not.toContain('<script>');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user