Skip to content

Commit ea3e925

Browse files
fix: sanitize threshold values in complexity SQL queries
Coerce threshold warn values through Number() and guard with isNaN before interpolating into SQL HAVING clauses, preventing malformed queries when non-numeric values are provided in config. Impact: 1 functions changed, 4 affected
1 parent 0337318 commit ea3e925

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/complexity.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,16 @@ export function complexityData(customDbPath, opts = {}) {
389389
if (aboveThreshold) {
390390
const conditions = [];
391391
if (thresholds.cognitive?.warn != null) {
392-
conditions.push(`fc.cognitive >= ${thresholds.cognitive.warn}`);
392+
const val = Number(thresholds.cognitive.warn);
393+
if (!Number.isNaN(val)) conditions.push(`fc.cognitive >= ${val}`);
393394
}
394395
if (thresholds.cyclomatic?.warn != null) {
395-
conditions.push(`fc.cyclomatic >= ${thresholds.cyclomatic.warn}`);
396+
const val = Number(thresholds.cyclomatic.warn);
397+
if (!Number.isNaN(val)) conditions.push(`fc.cyclomatic >= ${val}`);
396398
}
397399
if (thresholds.maxNesting?.warn != null) {
398-
conditions.push(`fc.max_nesting >= ${thresholds.maxNesting.warn}`);
400+
const val = Number(thresholds.maxNesting.warn);
401+
if (!Number.isNaN(val)) conditions.push(`fc.max_nesting >= ${val}`);
399402
}
400403
if (conditions.length > 0) {
401404
having = `AND (${conditions.join(' OR ')})`;

0 commit comments

Comments
 (0)