Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions web/packages/teleterm/src/ui/appContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export default AppContextProvider;

export function useAppContext() {
const ctx = React.useContext(AppReactContext);
// For debugging and diagnostic purposes.
window['teleterm'] = ctx;

// Attach the app context to the window for debugging and diagnostic purposes.
// Do not do this in the packaged app as this exposes privileged APIs through the window object.
if (process.env.NODE_ENV === 'development') {
window['teleterm'] = ctx;
}
return ctx;
}

Expand Down
24 changes: 23 additions & 1 deletion web/packages/teleterm/src/ui/boot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,30 @@ async function boot(): Promise<void> {
}
}

/**
* getElectronGlobals retrieves privileged APIs exposed through the contextBridge from preload.ts.
*
* It also immediately removes them from the window object so that if an attacker gets to execute
* arbitrary JS on the page, they don't get easy access to those privileged APIs.
*/
async function getElectronGlobals(): Promise<ElectronGlobals> {
return await window['electron'];
const globals = await window['electron'];
const globalsCopy = { ...globals };

// Technically, each value exposed through the contextBridge gets frozen. [1] Since we expose a
// promise returning an object however, we can delete properties from that object, effectively
// removing the APIs from the window object.
//
// We suspect that the semantics of this might change between Electron or Chromium updates.
// At the moment we're in the process of investigating how brittle this workaround is. [2]
//
// [1] https://www.electronjs.org/docs/latest/api/context-bridge#api
// [2] https://github.com/electron/electron/issues/38243
for (const property in globals) {
delete globals[property];
}

return globalsCopy;
}

function renderApp(content: React.ReactElement): void {
Expand Down