* Validates that a file path is within the project root for security purposes. * @param {string} filePath - The file path to validate * @throws {Error} If the path is outside the project root
(filePath)
| 270 | * @throws {Error} If the path is outside the project root |
| 271 | */ |
| 272 | function validatePathWithinProject(filePath) { |
| 273 | const projectRoot = path.join(__dirname, '../../..'); |
| 274 | const resolvedPath = path.resolve(filePath); |
| 275 | const normalizedRoot = path.resolve(projectRoot); |
| 276 | |
| 277 | // On Windows, paths are case-insensitive |
| 278 | const isWindows = process.platform === 'win32'; |
| 279 | const rel = path.relative( |
| 280 | isWindows ? normalizedRoot.toLowerCase() : normalizedRoot, |
| 281 | isWindows ? resolvedPath.toLowerCase() : resolvedPath |
| 282 | ); |
| 283 | if (rel.startsWith('..') || path.isAbsolute(rel)) { |
| 284 | const error = new Error(`Access denied: Path '${filePath}' is outside the project root`); |
| 285 | console.error(error.message); |
| 286 | throw error; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // Handle file reading for tests |
| 291 | ipcMain.handle('vscode:readFile', async (event, filePath) => { |
no test coverage detected
searching dependent graphs…