Skip to content

Commit

Permalink
Safely passing data to d3.html (apache#4842)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellethomas authored and timifasubaa committed May 31, 2018
1 parent 3ce3d86 commit 78bcd68
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion superset/assets/src/visualizations/big_number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import d3 from 'd3';
import d3tip from 'd3-tip';
import dompurify from 'dompurify';
import { d3FormatPreset, d3TimeFormatPreset } from '../modules/utils';

import './big_number.css';
Expand Down Expand Up @@ -153,7 +154,7 @@ function bigNumberVis(slice, payload) {

const renderTooltip = (d) => {
const date = formatDate(d[0]);
const value = f(d[1]);
const value = dompurify.sanitize(f(d[1]));
return `
<div>
<span style="margin-right: 10px;">${date}: </span>
Expand Down
3 changes: 2 additions & 1 deletion superset/assets/src/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'nvd3/build/nv.d3.min.css';
import mathjs from 'mathjs';
import moment from 'moment';
import d3tip from 'd3-tip';
import dompurify from 'dompurify';

import { getColorFromScheme } from '../modules/colors';
import AnnotationTypes, {
Expand Down Expand Up @@ -448,7 +449,7 @@ export default function nvd3Vis(slice, payload) {
`style="border: 2px solid ${series.highlight ? 'black' : 'transparent'}; background-color: ${series.color};"` +
'></div>' +
'</td>' +
`<td>${series.key}</td>` +
`<td>${dompurify.sanitize(series.key)}</td>` +
`<td>${yAxisFormatter(series.value)}</td>` +
'</tr>'
);
Expand Down
3 changes: 2 additions & 1 deletion superset/assets/src/visualizations/table.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import d3 from 'd3';
import dt from 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';
import dompurify from 'dompurify';

import { fixDataTableBodyHeight, d3TimeFormatPreset } from '../modules/utils';
import './table.css';
Expand Down Expand Up @@ -87,7 +88,7 @@ function tableVis(slice, payload) {
html = tsFormatter(val);
}
if (typeof (val) === 'string') {
html = `<span class="like-pre">${val}</span>`;
html = `<span class="like-pre">${dompurify.sanitize(val)}</span>`;
}
if (isMetric) {
html = slice.d3format(c, val);
Expand Down

0 comments on commit 78bcd68

Please sign in to comment.