fix: add input validation for /input and /resize API endpoints

- Add validation for input parameter in /input endpoint
- Add validation for cols/rows as positive integers in /resize endpoint
- Use standardized error responses with ApiErrorCode

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-21 16:20:56 +01:00
co-authored by Claude Opus 4.5
parent 3007abdbb2
commit ae7c003089
+13 -3
View File
@@ -25,6 +25,8 @@ import { generateClaudeMd } from '../templates/claude-md.js';
import { v4 as uuidv4 } from 'uuid';
import {
getErrorMessage,
ApiErrorCode,
createErrorResponse,
type CreateSessionRequest,
type RunPromptRequest,
type SessionInputRequest,
@@ -411,10 +413,14 @@ export class WebServer extends EventEmitter {
const session = this.sessions.get(id);
if (!session) {
return { success: false, error: 'Session not found' };
return createErrorResponse(ApiErrorCode.NOT_FOUND, 'Session not found');
}
session.write(input);
if (input === undefined || input === null) {
return createErrorResponse(ApiErrorCode.INVALID_INPUT, 'Input is required');
}
session.write(String(input));
return { success: true };
});
@@ -425,7 +431,11 @@ export class WebServer extends EventEmitter {
const session = this.sessions.get(id);
if (!session) {
return { success: false, error: 'Session not found' };
return createErrorResponse(ApiErrorCode.NOT_FOUND, 'Session not found');
}
if (!Number.isInteger(cols) || !Number.isInteger(rows) || cols < 1 || rows < 1) {
return createErrorResponse(ApiErrorCode.INVALID_INPUT, 'cols and rows must be positive integers');
}
session.resize(cols, rows);