Skip to content

Commit 74f57d0

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 98ca5f9 commit 74f57d0

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
@@ -1679,24 +1679,24 @@ function drawRawText(dom, txt /* , opt */) {
16791679
if (!isStr(stxt))
16801680
stxt = '<undefined>';
16811681

1682-
const mathjax = this.txt.mathjax || (settings.Latex === constants.Latex.AlwaysMathJax);
1683-
1684-
if (!mathjax && !('as_is' in this.txt)) {
1685-
const arr = stxt.split('\n');
1686-
stxt = '';
1687-
for (let i = 0; i < arr.length; ++i)
1688-
stxt += `<pre style='margin:0'>${arr[i]}</pre>`;
1689-
}
1690-
1691-
const frame = this.selectDom();
1682+
const mathjax = this.txt.mathjax || (settings.Latex === constants.Latex.AlwaysMathJax),
1683+
frame = this.selectDom();
16921684
let main = frame.select('div');
16931685
if (main.empty())
16941686
main = frame.append('div').attr('style', 'max-width:100%;max-height:100%;overflow:auto');
1695-
main.html(stxt);
1687+
else
1688+
main.html('');
16961689

16971690
// (re) set painter to first child element, base painter not requires canvas
16981691
this.setTopPainter();
16991692

1693+
if (!mathjax && !('as_is' in this.txt)) {
1694+
const arr = stxt.split('\n');
1695+
for (let i = 0; i < arr.length; ++i)
1696+
main.append('pre').style('margin', '0').text(arr[i]);
1697+
} else
1698+
main.text(stxt);
1699+
17001700
if (mathjax)
17011701
typesetMathjax(frame.node());
17021702

0 commit comments

Comments
 (0)