From 05d831df29be6d1b8f1d248ef408ee231fd15cf6 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Fri, 20 Dec 2019 11:28:10 +0100 Subject: [PATCH] Tooltip: preventing xss injections via the colors variable. (#21203) * Tooltip: preventing xss injections via the colors variable. * added xss check for single series tooltop color. * added sanitize to the hoverInfo.value. --- public/app/plugins/panel/graph/graph_tooltip.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/panel/graph/graph_tooltip.ts b/public/app/plugins/panel/graph/graph_tooltip.ts index 0c2dec69c1e..c8397616caf 100644 --- a/public/app/plugins/panel/graph/graph_tooltip.ts +++ b/public/app/plugins/panel/graph/graph_tooltip.ts @@ -1,6 +1,7 @@ import $ from 'jquery'; import { appEvents } from 'app/core/core'; import { CoreEvents } from 'app/types'; +import { sanitize } from 'app/core/utils/text'; export default function GraphTooltip(this: any, elem: any, dashboard: any, scope: any, getSeriesFn: any) { const self = this; @@ -256,12 +257,13 @@ export default function GraphTooltip(this: any, elem: any, dashboard: any, scope series = seriesList[hoverInfo.index]; - value = series.formatValue(hoverInfo.value); + value = series.formatValue(sanitize(hoverInfo.value)); + const color = sanitize(hoverInfo.color); + const label = sanitize(hoverInfo.label); seriesHtml += '
'; - seriesHtml += - ' ' + hoverInfo.label + ':
'; + seriesHtml += ' ' + label + ':
'; seriesHtml += '
' + value + '
'; plot.highlight(hoverInfo.index, hoverInfo.hoverIndex); } @@ -269,10 +271,10 @@ export default function GraphTooltip(this: any, elem: any, dashboard: any, scope self.renderAndShow(absoluteTime, seriesHtml, pos, xMode); } else if (item) { // single series tooltip + const color = sanitize(item.series.color); series = seriesList[item.seriesIndex]; group = '
'; - group += - ' ' + series.aliasEscaped + ':
'; + group += ' ' + series.aliasEscaped + ':
'; if (panel.stack && panel.tooltip.value_type === 'individual') { value = item.datapoint[1] - item.datapoint[2]; @@ -280,7 +282,7 @@ export default function GraphTooltip(this: any, elem: any, dashboard: any, scope value = item.datapoint[1]; } - value = series.formatValue(value); + value = series.formatValue(sanitize(value)); absoluteTime = dashboard.formatDate(item.datapoint[0], tooltipFormat);