"sql injection" for cypher

1,405 views
Skip to first unread message

Yaron Naveh

unread,
Jun 17, 2012, 10:06:44 AM6/17/12
to ne...@googlegroups.com
I've seen some posts on the matter but could not find anything conclusive.

I'm building a cypher query using user defined string:

qry = ... + "WHERE n.name='" + request["filter"] + "'"

how can I protect against "sql injection"? for example the filter could be ' OR '1'=='1

Is it enough to prefix all quotes with a backslash? Should I ban on some words to appear in the user string? The best would be to get a "parametwrized query" like syntax so the server would take care of this.

Michael Hunger

unread,
Jun 17, 2012, 10:08:15 AM6/17/12
to ne...@googlegroups.com
You should use parameters instead, 

Yaron Naveh

unread,
Jun 17, 2012, 10:57:29 AM6/17/12
to ne...@googlegroups.com
thanks

any idea how I can use a parameter to get a regex or "string contains" or "string like" semantics?

my original query is:

WHERE n.name =~ /.*value.*/

I'm not able to parameterize this. If not possible with regex, the other two options I mentioned are also good.

Yaron Naveh

unread,
Jun 17, 2012, 11:03:09 AM6/17/12
to ne...@googlegroups.com
got it, the query is

WHERE n.name =~ {name}

and parameter:

{name: ".*value.*"}

Michael Hunger

unread,
Jun 17, 2012, 11:16:52 AM6/17/12
to ne...@googlegroups.com
Exactly,

that should be in the docs, though. 

Michael

ryan

unread,
Apr 21, 2014, 5:17:46 PM4/21/14
to ne...@googlegroups.com
I have the same situation here where I am wanting to protect against SQL injection attacks.  I see this post is from 2012 so my first question is:  has the answer for the main question changed since 2012?

My next question (assuming answer to above is no) is I don't understand how this helps.  I am sure it's just me needing a better understanding of parameters.  If I have a query like this:

qry = ... + "WHERE n.name='" + usrName + "'"

and if userName = ' OR '1'=='1

I don't see how putting that in a parameter will help.  Does the parameter do something special vs. a non-parameterized query?

Michael Hunger

unread,
Apr 22, 2014, 8:51:40 AM4/22/14
to ne...@googlegroups.com
Parameters will help as they are not substituted as strings but during execution used as values in those expressions.

qry = " .... WHERE n.name= {usrName} ...."


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages