[Architecture] G1nation V2 Refactor
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* Validates that a path is within the workspace.
|
||||
* Prevents Path Traversal attacks.
|
||||
*/
|
||||
export function validatePath(workspaceRoot: string, targetPath: string): string {
|
||||
const absolutePath = path.resolve(workspaceRoot, targetPath);
|
||||
if (!absolutePath.startsWith(workspaceRoot)) {
|
||||
throw new Error(`Security Violation: Path traversal detected! Attempted to access ${absolutePath} which is outside the workspace ${workspaceRoot}`);
|
||||
}
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes terminal commands to prevent destructive actions.
|
||||
*/
|
||||
export function sanitizeCommand(command: string): string {
|
||||
const forbiddenPatterns = [
|
||||
/rm\s+-rf\s+\//,
|
||||
/mkfs/,
|
||||
/dd\s+if=/,
|
||||
/>\s*\/dev\/sd/,
|
||||
/:(){:|:&};:/ // Fork bomb
|
||||
];
|
||||
|
||||
for (const pattern of forbiddenPatterns) {
|
||||
if (pattern.test(command)) {
|
||||
throw new Error(`Security Violation: Destructive command pattern detected! Blocked: ${command}`);
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
Reference in New Issue
Block a user