Security: SQL injection risk from unvalidated ORDER BY direction and field tokens#1212
Open
tuanaiseo wants to merge 2 commits into
Open
Conversation
…irec `order-by.js` splits each order clause by space and directly interpolates both `field` and `direction` into SQL. `direction` is only uppercased, not validated to `ASC|DESC`, and `field` is not escaped for delimiter-breaking characters. A crafted `orderByFields` value can inject additional SQL or malformed expressions. Affected files: order-by.js, fields-select-fragment.js Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
…irec `order-by.js` splits each order clause by space and directly interpolates both `field` and `direction` into SQL. `direction` is only uppercased, not validated to `ASC|DESC`, and `field` is not escaped for delimiter-breaking characters. A crafted `orderByFields` value can inject additional SQL or malformed expressions. Affected files: order-by.js, fields-select-fragment.js Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
|
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.
Problem
order-by.jssplits each order clause by space and directly interpolates bothfieldanddirectioninto SQL.directionis only uppercased, not validated toASC|DESC, andfieldis not escaped for delimiter-breaking characters. A craftedorderByFieldsvalue can inject additional SQL or malformed expressions.Severity:
highFile:
packages/winnow/src/sql-query-builder/order-by.jsSolution
Parse order clauses with a strict parser: enforce
fieldin known schema anddirectionin a hardcoded enum (ASC,DESC) only. Reject invalid tokens instead of passing them through.Changes
packages/winnow/src/sql-query-builder/order-by.js(modified)packages/winnow/src/sql-query-builder/select/fields-select-fragment.js(modified)Testing