Skip to content

Fix NoSQL injection in threshold parameter (allocations-dao.js) - #121

Open
legit-app-ci[bot] wants to merge 1 commit into
masterfrom
agentic-appsec/sast-rem/f28f6875-10f3-4589-81d3-3c8d4fbb95cc
Open

Fix NoSQL injection in threshold parameter (allocations-dao.js)#121
legit-app-ci[bot] wants to merge 1 commit into
masterfrom
agentic-appsec/sast-rem/f28f6875-10f3-4589-81d3-3c8d4fbb95cc

Conversation

@legit-app-ci

@legit-app-ci legit-app-ci Bot commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Fixed a NoSQL injection vulnerability in app/data/allocations-dao.js (lines 56-114) where the threshold parameter was directly interpolated into a MongoDB $where clause without sanitization.

What changed

Replaced the vulnerable $where operator with native MongoDB comparison operators. The threshold parameter is now:

  1. Parsed to an integer (parseInt(threshold, 10))
  2. Validated to be in the range 0-99
  3. Used in a safe query: {userId: parsedUserId, stocks: {$gt: parsedThreshold}}

The original code allowed attackers to inject arbitrary JavaScript (e.g., 0';while(true){}' or 1'; return 1 == '1) that would execute server-side in MongoDB. The fix eliminates JavaScript execution entirely by using MongoDB's native $gt operator, which treats the threshold as data rather than executable code.

Review notes

The commented fix block in the original code has been uncommented and applied. The $where clause with string interpolation has been removed.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
E Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants