T09 · Insecure Skill Coding Practices
- Location
references/src-gateway-server-methods-agents-ts.txt:440- Finding
Avatar uploads trust client-controlled file type metadata without validating image content
- Content
View full analysis
; agentId: string; bytes: Buffer; extension: string; }): Promise<{ avatar: string; avatarUrl: string }> { const workspace = resolveAgentWorkspaceDir(params.cfg, params.agentId); const avatarDir = path.join(workspace, "avatars"); await fs.mkdir(avatarDir, { recursive: true }); const filename = `profile${params.extension}`; const absolutePath = path.join(avatarDir, filename); await fs.writeFile(absolutePath, params.bytes); const identityPath = path.join(workspace, DEFAULT_IDENTITY_FILENAME); await fs.appendFile(identityPath, `\n- Avatar: avatars/${filename}\n`, "utf-8"); return { avatar: `avatars/${filename}`, avatarUrl: `/avatar/${params.agentId}`, }; } ``` The corresponding upload handler derives the extension entirely from request metadata: ```ts const decoded = decodeAvatarUploadData(String(params.data ?? "")); if (!decoded || decoded.bytes.length === 0) { respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "invalid avatar image data")); return; } if (decoded.bytes.length > 2 * 1024 * 1024) { respond(false, undefined, errorShape(ErrorCodes.INVALID_REQ ...[truncated 2946 chars]- Remediation
View remediation
