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)
  • Loading branch information
gzdunek committed Oct 1, 2024
1 parent 761a5c0 commit 8af24ee
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 @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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

Expand Down Expand Up @@ -99,6 +99,14 @@ async function getElectronGlobals(): Promise<ElectronGlobals> {
vnetClient,
ptyServiceClient,
setupTshdEventContextBridgeService,
// 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 @@ -111,4 +111,6 @@ export type ElectronGlobals = {
readonly setupTshdEventContextBridgeService: (
listener: TshdEventContextBridgeService
) => void;
/** Exposes Electron's webUtils.getPathForFile. */
getPathForFile(file: File): string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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 @@ -75,6 +75,7 @@ export default class AppContext implements IAppContext {
setupTshdEventContextBridgeService: (
service: TshdEventContextBridgeService
) => void;
getPathForFile: (file: File) => string;
reloginService: ReloginService;
tshdNotificationsService: TshdNotificationsService;
headlessAuthenticationService: HeadlessAuthenticationService;
Expand All @@ -96,6 +97,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 @@ -38,6 +38,7 @@ export class MockAppContext extends AppContext {
vnetClient,
ptyServiceClient,
setupTshdEventContextBridgeService: () => {},
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 @@ -64,7 +64,8 @@ export interface IAppContext {
headlessAuthenticationService: HeadlessAuthenticationService;
tshd: TshdClient;
vnet: VnetClient;

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

/**
Expand Down

0 comments on commit 8af24ee

Please sign in to comment.