Skip to content

Commit 120ecf6

Browse files
committed
Fix - prevent code injection via plain text
TObjString painted via drawRawText function, which was using html for text. This is potentially risky therefore use text() function which does not parse inner text and does not create extra elements
1 parent 15793fb commit 120ecf6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

modules/base/ObjectPainter.mjs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,24 +1642,24 @@ function drawRawText(dom, txt /* , opt */) {
16421642
if (!isStr(stxt))
16431643
stxt = '<undefined>';
16441644

1645-
const mathjax = this.txt.mathjax || (settings.Latex === constants.Latex.AlwaysMathJax);
1646-
1647-
if (!mathjax && !('as_is' in this.txt)) {
1648-
const arr = stxt.split('\n');
1649-
stxt = '';
1650-
for (let i = 0; i < arr.length; ++i)
1651-
stxt += `<pre style='margin:0'>${arr[i]}</pre>`;
1652-
}
1653-
1654-
const frame = this.selectDom();
1645+
const mathjax = this.txt.mathjax || (settings.Latex === constants.Latex.AlwaysMathJax),
1646+
frame = this.selectDom();
16551647
let main = frame.select('div');
16561648
if (main.empty())
16571649
main = frame.append('div').attr('style', 'max-width:100%;max-height:100%;overflow:auto');
1658-
main.html(stxt);
1650+
else
1651+
main.html('');
16591652

16601653
// (re) set painter to first child element, base painter not requires canvas
16611654
this.setTopPainter();
16621655

1656+
if (!mathjax && !('as_is' in this.txt)) {
1657+
const arr = stxt.split('\n');
1658+
for (let i = 0; i < arr.length; ++i)
1659+
main.append('pre').style('margin', '0').text(arr[i]);
1660+
} else
1661+
main.text(stxt);
1662+
16631663
if (mathjax)
16641664
typesetMathjax(frame.node());
16651665

0 commit comments

Comments
 (0)