OrientDb sql injection and escaping characters

♀尐吖头ヾ 提交于 2019-12-10 17:09:29

问题


How can I prevent sql injection when programming against OrientDb using the OrientDB-NET.binary? Is there a way to escape special characters for Orient-SQL and work with string literals?

Example: I want to store this literal: me' or 1 = 1 ),'// and then be able to query it like

select from MyVertex where text = '...'

I'm having trouble doing this in OrientDb studio too.

I have found this post which is related to the Java driver, so I was wondering if there is something similar for .NET.


回答1:


You need to use parameterized queries.

These are queries that separate data from syntax, which is the root problem behind SQL injection.

In C#, using the OrientDB-NET binary, you want to do something like this (adapted from the OrientDB-NET wiki:

using (ODatabase database = new ODatabase("yourDatabase"))
{
    PreparedQuery query = new PreparedQuery("SELECT FROM MyVertex WHERE text = ?");
    var selectedValue = database
        .Query(query)
        .Run([***Your Input Here***])
        .SingleOrDefault();

    var text = selectedValue.GetField<string>("text");
}

You can check out the OrientDB-NET unit tests for PreparedQuery to see more examples of how you might do this.



来源:https://stackoverflow.com/questions/27843190/orientdb-sql-injection-and-escaping-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!