T09 · Insecure Skill Coding Practices
- Location
src/health-monitor.js:140- Finding
Unvalidated Metrics Can Bypass Health Alerts
- Content
View full analysis
a + b, 0) / scores.length; return average; } ``` The resulting score is consumed by each alert handler using the following unsafe fallback pattern: ```javascript const score = skillData.healthScore || 1.0; ``` ### Technical Analysis The implementation does not verify that the six supplied metrics are finite numbers in the documented range of `0` through `1`. Logical OR fallbacks treat valid zero values as missing. Consequently, a metric of `0`, which should indicate the worst possible result, is replaced with the healthy default value `0.70`. Malformed values can also bypass alert classification. For example, if a metric is `NaN`, the calculated average becomes `NaN`. Each handler then evaluates: ```javascript const score = skillData.healthScore || 1.0; ``` Because `NaN` is falsy, it is replaced with `1.0`, causing all alert thresholds to pass and producing an `ok` result. Non-numeric strings, infinities, negative numbers, and values above `1` are likewise accepted without validation and can corrupt or manipulate the calculated result. ### Attack Path 1. A caller invokes `checkSkillHealth()` with attacker-controlled or otherwise untrusted metrics. 2. The caller supplies zero values, `NaN`, malformed str ...[truncated 1493 chars]- Remediation
View remediation
{ const value = metrics[key]; if (!Number.isFinite(value) || value < 0 || value > 1) { throw new RangeError(`${key} must be a finite number between 0 and 1`); } return value; }); const average = scores.reduce((sum, value) => sum + value, 0) / scores.length; if (!Number.isFinite(average)) { throw new Error('Calculated health score is invalid'); } return average; } ``` The handlers should also avoid truthiness-based fallback behavior: ```javascript const score = skillData.healthScore; if (!Number.isFinite(score) || score < 0 || score > 1) { throw new RangeError('Health score must be a finite number between 0 and 1'); } ``` ]]>
