@@ -16,11 +16,43 @@ export async function POST(request: NextRequest) {
1616
1717 const params : CommandInput = await request . json ( )
1818
19- // Set default values
20- const workingDirectory = params . workingDirectory || process . cwd ( ) ;
21- const timeout = params . timeout || 30000 ;
22- const shell = params . shell || "/bin/bash" ;
19+ import { validatePathSegment } from '@/lib/core/security/input-validation'
2320
21+ // Validate input
22+ if ( ! params . command ) {
23+ return NextResponse . json (
24+ { error : "Command is required" } ,
25+ { status : 400 } ,
26+ )
27+ }
28+
29+ // Validate workingDirectory if provided
30+ if ( params . workingDirectory ) {
31+ const validation = validatePathSegment ( params . workingDirectory , {
32+ paramName : 'workingDirectory' ,
33+ allowDots : true // Allow relative paths like ../
34+ } )
35+ if ( ! validation . isValid ) {
36+ return NextResponse . json (
37+ { error : validation . error } ,
38+ { status : 400 } ,
39+ )
40+ }
41+ }
42+
43+ // Validate shell if provided - only allow safe shells
44+ const allowedShells = [ '/bin/bash' , '/bin/sh' , '/bin/zsh' ]
45+ if ( params . shell && ! allowedShells . includes ( params . shell ) ) {
46+ return NextResponse . json (
47+ { error : 'Invalid shell. Allowed shells: ' + allowedShells . join ( ', ' ) } ,
48+ { status : 400 } ,
49+ )
50+ }
51+
52+ // Set default values
53+ const workingDirectory = params . workingDirectory || process . cwd ( )
54+ const timeout = params . timeout || 30000
55+ const shell = params . shell || '/bin/bash'
2456 // Execute command
2557 const startTime = Date . now ( ) ;
2658 const result = await executeCommand (
0 commit comments