Series Chart HTML Formatting fix (#2403)

This commit is contained in:
GCHQ Developer 85297 2026-05-18 11:57:16 +01:00 committed by GitHub
parent 7ca4b3a13d
commit b090482bd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -15,6 +15,20 @@ import Utils from "../Utils.mjs";
const d3 = d3temp.default ? d3temp.default : d3temp;
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
*/
@ -222,6 +236,8 @@ class SeriesChart extends Operation {
.text(serie.name);
});
clearD3BoundData(svg.node());
return svg._groups[0][0].outerHTML;
}

View File

@ -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",
input: "100 100\n200 200\n300 300\n400 400\n500 500",