Series Chart HTML Formatting fix (#2403)
This commit is contained in:
parent
7ca4b3a13d
commit
b090482bd0
@ -15,6 +15,20 @@ import Utils from "../Utils.mjs";
|
|||||||
const d3 = d3temp.default ? d3temp.default : d3temp;
|
const d3 = d3temp.default ? d3temp.default : d3temp;
|
||||||
const nodom = nodomtemp.default ? nodomtemp.default: nodomtemp;
|
const nodom = nodomtemp.default ? nodomtemp.default: nodomtemp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes D3's internal bound data from a nodom tree before serialization.
|
||||||
|
* nodom serializes enumerable expando properties such as __data__ as attributes,
|
||||||
|
* so leaving them on attacker-controlled values can create executable markup.
|
||||||
|
*
|
||||||
|
* @param {Object} node
|
||||||
|
*/
|
||||||
|
function clearD3BoundData(node) {
|
||||||
|
delete node.__data__;
|
||||||
|
|
||||||
|
if (!node.childNodes) return;
|
||||||
|
node.childNodes.forEach(clearD3BoundData);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Series chart operation
|
* Series chart operation
|
||||||
*/
|
*/
|
||||||
@ -222,6 +236,8 @@ class SeriesChart extends Operation {
|
|||||||
.text(serie.name);
|
.text(serie.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
clearD3BoundData(svg.node());
|
||||||
|
|
||||||
return svg._groups[0][0].outerHTML;
|
return svg._groups[0][0].outerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,17 @@ TestRegister.addTests([
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Series chart escapes x-axis values in serialized SVG",
|
||||||
|
input: `s,x"><script>globalThis.seriesChartInjected=1</script><g a=",1`,
|
||||||
|
unexpectedMatch: /<script>|__data__=/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Series chart",
|
||||||
|
"args": ["Line feed", "Comma", "", 1, "red"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Heatmap chart",
|
name: "Heatmap chart",
|
||||||
input: "100 100\n200 200\n300 300\n400 400\n500 500",
|
input: "100 100\n200 200\n300 300\n400 400\n500 500",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user