Skip to content

Commit

Permalink
Fix XSS in New File dialog.
Browse files Browse the repository at this point in the history
Commit replaces call to innerHTML with a call to innerText to ensure
user supplied text will not create elements in the DOM. An alternative
to this approach would be to sanitize user input before adding it to the
DOM.

Signed-off-by: Casey Flynn <caseyflynn@google.com>
  • Loading branch information
caseyflynn-google committed Jan 28, 2020
1 parent f5209b3 commit 791b576
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/browser/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export abstract class AbstractDialog<T> extends BaseWidget {
if (this.acceptButton) {
this.acceptButton.disabled = !DialogError.getResult(error);
}
this.errorMessageNode.innerHTML = DialogError.getMessage(error);
this.errorMessageNode.innerText = DialogError.getMessage(error);
}

protected addCloseAction<K extends keyof HTMLElementEventMap>(element: HTMLElement, ...additionalEventTypes: K[]): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ export class WorkspaceCommandContribution implements CommandContribution {
}
// check and validate each sub-paths
if (name.split(/[\\/]/).some(file => !file || !validFilename(file) || /^\s+$/.test(file))) {
return `The name <strong>${this.trimFileName(name)}</strong> is not a valid file or folder name.`;
return `The name "${this.trimFileName(name)}" is not a valid file or folder name.`;
}
const childUri = new URI(parent.uri).resolve(name).toString();
const exists = await this.fileSystem.exists(childUri);
if (exists) {
return `A file or folder <strong>${this.trimFileName(name)}</strong> already exists at this location.`;
return `A file or folder "${this.trimFileName(name)}" already exists at this location.`;
}
return '';
}
Expand Down

0 comments on commit 791b576

Please sign in to comment.