Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[v14] Take the file path from webUtils.getPathForFile instead of File.path #47014

Merged
merged 1 commit into from
Oct 1, 2024
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
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>;
}
Loading