fix: SQL Injection via parameterized queries (#4169)#12
Open
aglichandrap wants to merge 1 commit into
Open
Conversation
- voter.service.ts: Convert stakeKey from string interpolation to $1 parameterized query, add hex validation - drep.service.ts: Convert search query from single-quote doubling to proper parameterized queries, escape array interpolations - getDReps.ts: Add queryParams parameter to support parameterized search - Add unit tests proving injection payloads are rejected/parameterized Closes IntersectMBO/govtool#4169
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: SQL Injection via Parameterized Queries
Closes IntersectMBO/govtool#4169
Problem
The
GET /voters/:stakeKey/delegationendpoint was vulnerable to SQL injection (CVSS 8.6). ThestakeKeyURL parameter was interpolated directly into a raw SQL template literal, allowing UNION-based injection to read the entire database.Secondary vectors existed in
drep.service.tswhere search queries used weak single-quote doubling and DRep view arrays were interpolated without escaping.Changes
backend/src/voter/voter.service.ts(Primary fix):DECODE('${stakeKey}', 'hex')→DECODE($1, 'hex')with[stakeKey]parameter arrayBadRequestExceptionfor invalid inputbackend/src/drep/drep.service.ts(Secondary fixes):$1/$2parameterized queriesnameFilteredDRepViewsarray interpolationdRepViewsarray interpolationsearchParamsarray to query execution callsbackend/src/queries/getDReps.ts:queryParamsparameter togetAllDRepsQueryfunction signatureTest files added:
backend/src/voter/__tests__/voter.service.spec.ts— Tests SQL injection payloads (UNION, OR 1=1, special chars) are rejected; verifies parameterized$1usagebackend/src/drep/__tests__/drep.service.spec.ts— Tests search parameterization and array escapingSecurity Notes