mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:18:37 +00:00
fix(security): OC-53 enforce 2MB prompt size limit to prevent ACP DoS — Aether AI Agent
This commit is contained in:
committed by
Peter Steinberger
parent
c9dee59266
commit
732e53151e
@@ -40,6 +40,9 @@ import { parseSessionMeta, resetSessionIfNeeded, resolveSessionKey } from "./ses
|
|||||||
import { defaultAcpSessionStore, type AcpSessionStore } from "./session.js";
|
import { defaultAcpSessionStore, type AcpSessionStore } from "./session.js";
|
||||||
import { ACP_AGENT_INFO, type AcpServerOptions } from "./types.js";
|
import { ACP_AGENT_INFO, type AcpServerOptions } from "./types.js";
|
||||||
|
|
||||||
|
// Maximum allowed prompt size (2MB) to prevent DoS via memory exhaustion (CWE-400, GHSA-cxpw-2g23-2vgw)
|
||||||
|
const MAX_PROMPT_BYTES = 2 * 1024 * 1024;
|
||||||
|
|
||||||
type PendingPrompt = {
|
type PendingPrompt = {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
sessionKey: string;
|
sessionKey: string;
|
||||||
@@ -267,6 +270,13 @@ export class AcpGatewayAgent implements Agent {
|
|||||||
const displayCwd = shortenHomePath(session.cwd);
|
const displayCwd = shortenHomePath(session.cwd);
|
||||||
const message = prefixCwd ? `[Working directory: ${displayCwd}]\n\n${userText}` : userText;
|
const message = prefixCwd ? `[Working directory: ${displayCwd}]\n\n${userText}` : userText;
|
||||||
|
|
||||||
|
// Guard against oversized prompts that could cause memory exhaustion (DoS)
|
||||||
|
if (Buffer.byteLength(message, "utf-8") > MAX_PROMPT_BYTES) {
|
||||||
|
throw new Error(
|
||||||
|
`Prompt exceeds maximum allowed size of ${MAX_PROMPT_BYTES} bytes`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise<PromptResponse>((resolve, reject) => {
|
return new Promise<PromptResponse>((resolve, reject) => {
|
||||||
this.pendingPrompts.set(params.sessionId, {
|
this.pendingPrompts.set(params.sessionId, {
|
||||||
sessionId: params.sessionId,
|
sessionId: params.sessionId,
|
||||||
|
|||||||
Reference in New Issue
Block a user