Skip to content

Commit 8e511a0

Browse files
authored
fix: Don't use HTML in panel titles, treat as text (#2365) (#2366)
- Golden Layout was setting the title in panel titles with `.html()` method, which allows remote code execution, and potentially could craft a notebook with a malicious name that could run arbitrary JS - Instead just use `.text` and treat it like text, as we should. - Tested on DHC - created a notebook with the name `<img src=q onerror=prompt(1)>.py`. It now appears correctly as text and does not pop up an alert message. Also verified that title still appears in italics when in "preview" mode. - Fixes DH-18645
1 parent 1d8d9c3 commit 8e511a0

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

packages/golden-layout/src/controls/DragProxy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default class DragProxy extends EventEmitter {
9090
'title',
9191
stripTags(this._contentItem.config.title ?? '')
9292
);
93-
this.element.find('.lm_title').html(this._contentItem.config.title ?? '');
93+
this.element.find('.lm_title').text(this._contentItem.config.title ?? '');
9494
this.childElementContainer = this.element.find('.lm_content');
9595
this.childElementContainer.append(contentItem.element);
9696

packages/golden-layout/src/controls/Tab.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default class Tab {
9898
setTitle(title = '') {
9999
// Disabling for illumon project, we want to manage our own tooltips
100100
// this.element.attr( 'title', lm.utils.stripTags( title ) );
101-
this.titleElement.html(title);
101+
this.titleElement.text(title);
102102
}
103103

104104
/**

packages/golden-layout/test/title-tests.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ describe('content items are abled to to emit events that bubble up the tree', fu
6666
it('supports html in title', function () {
6767
itemWithTitle.container.setTitle('title <b>with</b> html');
6868
expect(stack.header.tabs[0].element.find('.lm_title').html()).toBe(
69-
'title <b>with</b> html'
69+
'title &lt;b&gt;with&lt;/b&gt; html'
7070
);
7171
expect(stack.header.tabs[0].element.find('.lm_title').text()).toBe(
72-
'title with html'
72+
'title <b>with</b> html'
7373
);
74-
// expect( stack.header.tabs[ 0 ].element.attr( 'title' ) ).toBe( 'title with html' );
7574
});
7675

7776
it('destroys the layout', function () {

0 commit comments

Comments
 (0)