Skip to content

Commit

Permalink
Merge pull request apache#43 from michellethomas/cherrypick_clean_htm…
Browse files Browse the repository at this point in the history
…l_data

Safely passing data to d3.html
  • Loading branch information
michellethomas authored May 9, 2018
2 parents 3b233fb + d05842f commit 75d57a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion superset/assets/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 '../javascripts/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/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nv from 'nvd3';
import mathjs from 'mathjs';
import moment from 'moment';
import d3tip from 'd3-tip';
import dompurify from 'dompurify';

import { getColorFromScheme } from '../javascripts/modules/colors';
import AnnotationTypes, {
Expand Down Expand Up @@ -420,7 +421,7 @@ 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/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 '../javascripts/modules/utils';
import './table.css';
Expand Down Expand Up @@ -81,7 +82,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 75d57a3

Please sign in to comment.