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 5a87ee3 commit 2edbba6
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 @@ -108,6 +108,14 @@ async function getElectronGlobals(): Promise<ElectronGlobals> {
tshClient,
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 @@ -110,4 +110,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 @@ -74,6 +74,7 @@ export default class AppContext implements IAppContext {
setupTshdEventContextBridgeService: (
service: TshdEventContextBridgeService
) => void;
getPathForFile: (file: File) => string;
reloginService: ReloginService;
tshdNotificationsService: TshdNotificationsService;
headlessAuthenticationService: HeadlessAuthenticationService;
Expand All @@ -91,6 +92,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 @@ -33,6 +33,7 @@ export class MockAppContext extends AppContext {
tshClient: tshdClient,
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 @@ -62,6 +62,7 @@ export interface IAppContext {
connectMyComputerService: ConnectMyComputerService;
headlessAuthenticationService: HeadlessAuthenticationService;
tshd: TshdClient;

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

0 comments on commit 2edbba6

Please sign in to comment.