Skip to content

More validation for query parameters #354

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
merged 2 commits into from
Apr 19, 2018

Conversation

lutovich
Copy link
Contributor

Driver expects query parameters to either be undefined/null or an object. This was previously not enforced and illegal parameters, like strings or arrays, were sent to the database. This resulted in a protocol violation and database closed the connection. Users were only able to see the actual error/stacktrace in the database logs. Driver received a ServiceUnavailable or SessionExpired error.

This PR adds validation of query parameters. It also prohibits nodes, relationships, and paths from being used as query parameters in the driver.

Resolves #340

@lutovich lutovich requested a review from ali-ince April 16, 2018 15:04
@lutovich lutovich force-pushed the 1.6-validate-params branch from f493c15 to 278248a Compare April 17, 2018 12:18
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

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

Changes look good to me. Only added a couple of comments.

}

function assertQueryParameters(obj) {
if (!isObject(obj) && Boolean(obj)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isObject(obj) already includes the condition Boolean(obj), maybe just remove && Boolean(obj) here?

@@ -39,8 +39,29 @@ function isEmptyObjectOrNull(obj) {
}

function isObject(obj) {
const type = typeof obj;
return type === 'function' || type === 'object' && Boolean(obj);
return typeof obj === 'object' && !Array.isArray(obj) && Boolean(obj);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know an immediate replacement but not sure if Boolean(obj) is the correct thing to check here. Here are a couple of console tests;

isObject(new Date()) returns true
isObject(new Number()) returns true

Do you think we can have a better way of checking for actual object types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will replace Boolean(obj) with obj !== null which is much less cryptic.

Technically, Date and Number are objects so maybe it's okay to accept them. We should probably support parameters given like this:

class PersonParams {
  constructor(name, age) {
    this.name = name;
    this.age = age;  
  }
}

session.run('CREATE (:Peson {name: $name, age: $age})', new PersonParams('Bob', 42))

and that is why I'm not sure how to allow these but disallow Date and Number.

@lutovich lutovich force-pushed the 1.6-validate-params branch from 278248a to b0b418b Compare April 19, 2018 09:47
Driver expects query parameters to either be undefined/null or an
object. This was previously not enforced and illegal parameters,
like strings or arrays, were sent to the database. This resulted
in a protocol violation and database closed the connection. Users
were only able to see the actual error/stacktrace in the database
logs. Driver received a `ServiceUnavailable` or `SessionExpired`
error.

This commit adds validation of query parameters. It also prohibits
nodes, relationships and paths from being used as query parameters
in the driver.
@lutovich lutovich force-pushed the 1.6-validate-params branch from b0b418b to 40f5258 Compare April 19, 2018 09:51
@lutovich lutovich merged commit 4908a71 into neo4j:1.6 Apr 19, 2018
@lutovich lutovich deleted the 1.6-validate-params branch April 19, 2018 12:32
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.

2 participants