Skip to content

Security: Webviews can trigger arbitrary keyboard shortcuts in the main workbench #319593

@ammaraskar

Description

@ammaraskar

The default set of webview message handlers have an event called did-keydown:

this._register(this.on('did-keydown', (data) => {
// Electron: workaround for https://github.com/electron/electron/issues/14258
// We have to detect keyboard events in the <webview> and dispatch them to our
// keybinding service because these events do not bubble to the parent window anymore.
this.handleKeyEvent('keydown', data);
}));

This is used to bring out keydown events from the webview frame so keybindings work when you're focused on the webview:

// Also forward events before the contents of the webview have loaded
window.addEventListener('keydown', handleInnerKeydown);

Unfortunately this can create a bit of a security issue. If there is XSS in a webview or it intentionally allows scripts, it can trigger a series of dangerous keydown events like:

"Terminal: New Terminal Window" Ctrl+Shift+Alt+` followed by changing focus F6 and then "Terminal: Paste Into Active Terminal" Ctrl+Shift+V.

I don't know what a good solution is in terms of balancing this issue with usability because it wouldn't be the best user-experience to just have shortcuts not work entirely when you're clicked on a webview.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions