T09 · Insecure Skill Coding Practices
Warning
- Location
index.js:221- Finding
Unbounded Prediction Horizon Enables Synchronous Denial of Service
- Content
View full analysis
Math.max(0, Math.min(1, x))); // Check minimum data points if (normalizedData.length < opts.minDataPoints) { return { error: `Insufficient data: need at least ${opts.minDataPoints} points, got ${normalizedData.length}`, recommendation: { action: ScalingAction.UNKNOWN, reason: 'Need more historical data' } }; } // Calculate predictions using multiple methods const linearResult = predictLinear(normalizedData, opts.horizon); const expResult = predictExponential(normalizedData, opts.horizon, opts.smoothingFactor); ``` Both prediction functions use the unchecked value as a synchronous loop bound: ```javascript function predictLinear(data, steps) { const { slope, intercept, r2 } = linearRegression(data); const predictions = []; for (let i = 0; i < steps; i++) { predictions.push(intercept + slope * (data.length + i)); } return { predictions, confidence: Math.max(0, Math.min(1, r2)) }; } ``` ```javascript function predictExponential(data, steps, factor = DEFAULT_OPTIONS.smoothingFactor) { const ema = exponentialMovingAverage(d ...[truncated 2826 chars]- Remediation
View remediation
MAX_PREDICTION_STEPS ) { throw new RangeError( `Prediction steps must be an integer between 1 and ${MAX_PREDICTION_STEPS}` ); } } function predictLinear(data, steps) { validatePredictionSteps(steps); const { slope, intercept, r2 } = linearRegression(data); const predictions = []; for (let i = 0; i < steps; i++) { predictions.push(intercept + slope * (data.length + i)); } return { predictions, confidence: Math.max(0, Math.min(1, r2)) }; } function predictExponential( data, steps, factor = DEFAULT_OPTIONS.smoothingFactor ) { validatePredictionSteps(steps); // Continue with prediction logic. } ``` The main `predict` function should validate `opts.horizon` before invoking either prediction method, while the validation inside each exported lower-level function should remain as defense in depth. ]]>
