Skip to content

Security: SQL injection risk from unvalidated ORDER BY direction and field tokens#1212

Open
tuanaiseo wants to merge 2 commits into
koopjs:masterfrom
tuanaiseo:contribai/fix/security/sql-injection-risk-from-unvalidated-orde
Open

Security: SQL injection risk from unvalidated ORDER BY direction and field tokens#1212
tuanaiseo wants to merge 2 commits into
koopjs:masterfrom
tuanaiseo:contribai/fix/security/sql-injection-risk-from-unvalidated-orde

Conversation

@tuanaiseo
Copy link
Copy Markdown

Problem

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.

Severity: high
File: packages/winnow/src/sql-query-builder/order-by.js

Solution

Parse order clauses with a strict parser: enforce field in known schema and direction in 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

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

…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>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 5, 2026

⚠️ No Changeset found

Latest commit: eee0b32

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant