Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { concurrently } from "utils/concurrently";
import { ShellBackend } from 'backend/shell-backend';
import { URL } from 'url';
import { NotificationService } from "backend/notification/notification-service";
import * as path from 'path';

interface FXCode {
getRootPath(): string;
Expand Down Expand Up @@ -68,7 +69,12 @@ export class FXCodeService implements AppContribution {

this.shellBackend.expressApp.get('/vscode-remote-resource', (req, res) => {
if (this.fxcode) {
res.sendFile(this.fxcode.getRemoteResourcePath(getUrlQuery(req.url)));
const resourcePath = this.fxcode.getRemoteResourcePath(getUrlQuery(req.url));
if (!resourcePath || !isPathInside(resourcePath, this.configService.sdkRootFXCode)) {
res.status(400).send('Invalid resource path');
return;
}
res.sendFile(resourcePath);
} else {
res.send('FXCode not started it seems, rip');
}
Expand Down Expand Up @@ -167,3 +173,11 @@ function getUrlQuery(url: string): Record<string, string> {
return acc;
}, {});
}

function isPathInside(candidate: string, root: string): boolean {
const resolvedRoot = path.resolve(root);
const resolvedCandidate = path.resolve(candidate);
const relativePath = path.relative(resolvedRoot, resolvedCandidate);

return relativePath === '' || (!!relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath));
}
Loading