|
| 1 | +import * as path from 'node:path'; |
| 2 | + |
| 3 | +import type { AppManager } from '../../AppManager'; |
| 4 | +import type { IParseAppPackageResult } from '../../compiler'; |
| 5 | +import type { IAppStorageItem } from '../../storage'; |
| 6 | +import { BaseRuntimeSubprocessController, type ProcessConfiguration } from '../base/BaseRuntimeSubprocessController'; |
| 7 | + |
| 8 | +export class NodeRuntimeSubprocessController extends BaseRuntimeSubprocessController { |
| 9 | + private readonly nodeBin = 'node'; |
| 10 | + |
| 11 | + private readonly scriptRuntimePath: string; |
| 12 | + |
| 13 | + constructor(manager: AppManager, appPackage: IParseAppPackageResult, storageItem: IAppStorageItem) { |
| 14 | + super('node', manager, appPackage, storageItem); |
| 15 | + |
| 16 | + this.scriptRuntimePath = require.resolve('../../../../node-runtime/dist/main.js'); |
| 17 | + } |
| 18 | + |
| 19 | + protected buildProcessConfiguration(): ProcessConfiguration { |
| 20 | + const allowedDirs = [this.tempFilePath, path.resolve(path.dirname(this.scriptRuntimePath), '..', '..'), this.appsEnginePath]; |
| 21 | + |
| 22 | + const args = [ |
| 23 | + '--permission', |
| 24 | + ...allowedDirs.map((dir) => `--allow-fs-read=${dir}`), |
| 25 | + this.scriptRuntimePath, |
| 26 | + '--subprocess', |
| 27 | + this.appPackage.info.id, |
| 28 | + '--spawnId', |
| 29 | + String(this.spawnId++), |
| 30 | + ]; |
| 31 | + |
| 32 | + // SECURITY: We control the command, the arguments and the script that will be executed. |
| 33 | + return { |
| 34 | + command: this.nodeBin, |
| 35 | + args, |
| 36 | + options: { |
| 37 | + env: { |
| 38 | + PATH: process.env.PATH, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }; |
| 42 | + } |
| 43 | +} |
0 commit comments