Skip to content

Add order keywords whitelist #2919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

fixe
Copy link
Contributor

@fixe fixe commented Jan 13, 2015

Fixes #2906.
Breaking change: it is mandatory to provide the order when using the array notation.

@mickhansen I think we should create an abstract query-generator test file and add the missing tests there. I can also check if the number of arguments in the array is 1 and keep the BC in that case. Thoughts?

@mickhansen
Copy link
Contributor

@fixe if 2nd argument is empty default to ASC probably? (and then revert tests)

@mickhansen
Copy link
Contributor

As for unit testing the query generator, #2690
We generally need a larger sql unit testing suite.

if (subQuery && (Array.isArray(t) && !(t[0] instanceof Model) && !(t[0].model instanceof Model))) {
subQueryOrder.push(this.quote(t, model));
}
mainQueryOrder.push(this.quote(t, model));
}.bind(this));
} else {
if (Array.isArray(options.order)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition will never be true. When the order is sent as a string, we'll probably need to parse it and look for the ASC/DESC keywords no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, that condition will never be reached.
I'm not sure about parsing, i prefer people use the correct syntax (but don't we all)

@fixe fixe force-pushed the bugfix/whitelist-order-keywords branch from a24bd6e to a93a3a7 Compare January 13, 2015 23:39
@fixe
Copy link
Contributor Author

fixe commented Jan 13, 2015

@mickhansen PR updated. I need more feedback on testing this though :-)

@@ -525,7 +525,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
],
order: [
User.rawAttributes.id,
[Product, 'id']
[Product, 'id', 'ASC']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should still not be needed.
But not sure exactly how we would go about that.

@mickhansen
Copy link
Contributor

@fixe something like:

expect(
  User.findAll({
    order: [
      ['id', ';DELETE YOLO INJECTIONS']
    ]
  })
).to.throw();

And perhaps add one for using an include and ordering by that include too.

@mickhansen mickhansen merged commit a93a3a7 into sequelize:master Jan 15, 2015
@fixe fixe deleted the bugfix/whitelist-order-keywords branch January 18, 2015 00:02
@mickhansen
Copy link
Contributor

Need to expand this to cover DESC NULLS LAST, ASC NULLS LAST and support for .literal()

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.

sql injection risk when when using order.
3 participants