Skip to content

Commit 760a1d9

Browse files
committed
fix: Don't use innerHTML to populate drag item (DH-18645) (#2378)
- We were using `innerHTML` with the text of the name of the file to create the drag placeholder content - Instead, inject the name using `innerText` so it is escaped properly - Tested by naming a file `<img src=q onerror=prompt(1)>.py`, and then attempting to move it. It no longer triggered the popup.
1 parent e141551 commit 760a1d9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/file-explorer/src/FileList.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ export function FileList(props: FileListProps): JSX.Element {
198198
itemList.current?.resetMouseState();
199199

200200
const newDragPlaceholder = document.createElement('div');
201-
newDragPlaceholder.innerHTML = `<div class="dnd-placeholder-content">${getDragPlaceholderText()}</div>`;
201+
const dndPlaceholderContent = document.createElement('div');
202+
dndPlaceholderContent.className = 'dnd-placeholder-content';
203+
dndPlaceholderContent.innerText = getDragPlaceholderText() ?? '';
204+
newDragPlaceholder.appendChild(dndPlaceholderContent);
202205
newDragPlaceholder.className = 'file-list-dnd-placeholder';
203206
document.body.appendChild(newDragPlaceholder);
204207
e.dataTransfer.setDragImage(newDragPlaceholder, 0, 0);

0 commit comments

Comments
 (0)