T09 · Insecure Skill Coding Practices
- Location
index.ts:38- Finding
Unbounded Generation Count Enables Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
index.ts, lines 38-51, 220-232, and 279
Vulnerability Type: Uncontrolled resource consumption caused by missing input validation
Risk Level: HighVulnerable Code
ts async create(task: { demandId?: string; prompt: string; model?: string; params?: Record<string, any>; count: number; }): Promise<string> { const id = `GEN-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; const model = task.model || this.api.config?.defaultModel || "flux"; const genTask: GenerationTask = { id, demandId: task.demandId, prompt: task.prompt, model, params: task.params || {}, count: task.count, status: "queued", createdAt: new Date(), updatedAt: new Date(), };ts // Generate mock results task.results = []; for (let i = 0; i < task.count; i++) { task.results.push({ materialId: `MAT-${id}-${i}`, prompt: task.prompt, model: task.model, params: task.params, score: Math.random() * 10, // Random score 0-10 status: "generated" }); }ts count: { type: "number", help: "生成数量 (默认4)", default: 4 },Technical Analysis
The externally supplied
countvalue is accepted as a generic number and copied directly into the generation task. No check ensures that it is a finite positive integer or that it remains below a safe maximum.After a two-second delay,
simulateCompletionuses this value as the bound of a synchronous loop. Every iteration allocates a result object and appends it to an in-memory array. An excessively large finite count can therefore monopolize the JavaScript event loop and cause substantial memory allocation.Although the code reads the
maxConcurrentconfiguration value, it does not implement a queue or enforce concurrency limits. An attacker could consequently create multiple oversized tasks before their timers execute, amplifying resource consumption.Attack Path
- An attacker or ...[truncated 1222 chars]
- Remediation
View remediation
Remediation Suggestions
- Validate
countat the command boundary and again insidecreate, so internal callers cannot bypass validation. - Require the value to be a finite positive integer:
ts const MAX_RESULTS_PER_TASK = 100; if ( !Number.isFinite(task.count) || !Number.isInteger(task.count) || task.count < 1 || task.count > MAX_RESULTS_PER_TASK ) { throw new Error( `count must be an integer between 1 and ${MAX_RESULTS_PER_TASK}` ); }- Select a conservative maximum based on measured memory and execution costs.
- Enforce per-caller rate limits and quotas if caller identity is available.
- Implement a real bounded queue that enforces
maxConcurrentinstead of merely reading the configuration value. - Avoid large synchronous loops. Process bounded batches with cancellation checks and yield control between batches.
- Add aggregate limits for queued tasks and generated results to prevent many individually valid requests from exhausting resources.
- Add automated tests for zero, negative, fractional, non-finite, and excessively large count values.
- Validate
