Skip to content

Commit

Permalink
Take the file path from webUtils.getPathForFile instead of `File.pa…
Browse files Browse the repository at this point in the history
…th` (#46971)

(cherry picked from commit 8af24ee)
  • Loading branch information
gzdunek committed Oct 1, 2024
1 parent cc5fcf8 commit 0997a04
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion web/packages/teleterm/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { contextBridge } from 'electron';
import { contextBridge, webUtils } from 'electron';
import { ChannelCredentials, ServerCredentials } from '@grpc/grpc-js';

import createTshClient from 'teleterm/services/tshd/createClient';
Expand Down Expand Up @@ -83,6 +83,14 @@ async function getElectronGlobals(): Promise<ElectronGlobals> {
tshClient,
ptyServiceClient,
subscribeToTshdEvent,
// Ideally, we would call this function only on the preload side,
// but there's no easy way to access the file there (constructing the tshd
// call for a file transfer happens entirely on the renderer side).
//
// However, the risk of exposing this API is minimal because the file passed
// in cannot be constructed in JS (it must be selected in the file picker).
// So an attacker cannot pass a fake file to probe the file system.
getPathForFile: file => webUtils.getPathForFile(file),
};
}

Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleterm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ export type ElectronGlobals = {
readonly tshClient: TshClient;
readonly ptyServiceClient: PtyServiceClient;
readonly subscribeToTshdEvent: SubscribeToTshdEvent;
/** Exposes Electron's webUtils.getPathForFile. */
getPathForFile(file: File): string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function DocumentTerminal(props: {
{
serverUri: doc.serverUri,
login: doc.login,
source: file.path,
source: ctx.getPathForFile(file),
destination: destinationPath,
},
abortController
Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleterm/src/ui/appContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class AppContext implements IAppContext {
* request gets canceled by the client.
*/
subscribeToTshdEvent: SubscribeToTshdEvent;
getPathForFile: (file: File) => string;
reloginService: ReloginService;
tshdNotificationsService: TshdNotificationsService;
headlessAuthenticationService: HeadlessAuthenticationService;
Expand All @@ -93,6 +94,7 @@ export default class AppContext implements IAppContext {
this.mainProcessClient = mainProcessClient;
this.notificationsService = new NotificationsService();
this.configService = this.mainProcessClient.configService;
this.getPathForFile = config.getPathForFile;
this.usageService = new UsageService(
tshClient,
this.configService,
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleterm/src/ui/fixtures/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class MockAppContext extends AppContext {
tshClient: tshdClient,
ptyServiceClient,
subscribeToTshdEvent: () => {},
getPathForFile: () => '',
});
}
}
3 changes: 2 additions & 1 deletion web/packages/teleterm/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface IAppContext {
connectMyComputerService: ConnectMyComputerService;
headlessAuthenticationService: HeadlessAuthenticationService;
tshd: TshClient;

/** Exposes Electron's webUtils.getPathForFile. */
getPathForFile: (file: File) => string;
pullInitialState(): Promise<void>;
}

0 comments on commit 0997a04

Please sign in to comment.