manticoresoftware / manticoresearch

Easy to use open source fast database for search | Good alternative to Elasticsearch now | Drop-in replacement for E in the ELK soon
https://manticoresearch.com
GNU General Public License v3.0
8.87k stars 490 forks source link

Prepared statements like in mysql #1124

Open UtfCube opened 1 year ago

UtfCube commented 1 year ago

Translation:

Is your feature request related to a problem? Please describe. Currently, there is no support for prepared statements. Because of this, SQL injections are possible and it is inconvenient to work with Manticore through ORM and native drivers.

Describe the solution you'd like Add support for prepared statements like in MySQL.


Original request:

Is your feature request related to a problem? Please describe. Сейчас нет поддержки prepared statements. Из-за этого возможны sql-инъекции и не удобно работать с мантикорой через орм и нативные драйверы

Describe the solution you'd like Добавить поддержку prepared statements как в mysql

Additional context Необходима помощь с компиляцией проекта и возможно бегло ввести в курс дела по основным архитектурным решениям (или просто указать в каком месте надо реализовать этот функционал и в каком виде)

sanikolaev commented 1 year ago

По компиляции почитайте, пожалуйста, https://manual.manticoresearch.com/dev/Installation/Compiling_from_sources#Building-using-CI-Docker

Если что непонятно - спрашивайте. По архитектуре в понедельник обсужу с командой и допишем сюда.

UtfCube commented 1 year ago

Хорошо, ещё попробую поискать как в mysql реализовано. Но если вы знаете ресурс, где можно почитать, очень бы помогло.

UtfCube commented 1 year ago

И ещё - не бейте сильно палками за код) на плюсах не писал года 3

sanikolaev commented 1 year ago

Хорошо, ещё попробую поискать как в mysql реализовано. Но если вы знаете ресурс, где можно почитать, очень бы помогло.

Думаю, что без изучения https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_command_phase_ps.html не обойтись.

UtfCube commented 1 year ago

Хорошо, ещё попробую поискать как в mysql реализовано. Но если вы знаете ресурс, где можно почитать, очень бы помогло.

Думаю, что без изучения https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_command_phase_ps.html не обойтись.

Понял, спасибо

UtfCube commented 1 year ago

@sanikolaev потихонечку начали курить доку и разбираться в коде, пока не можем найти вашу реализацию самого протокола mysql. Думаю доскональное изучение вашей реализации нам точно понадобится) Не могли бы скинуть ссылочку в репу, откуда стоит начать смотреть?

tomatolog commented 1 year ago

файл https://github.com/manticoresoftware/manticoresearch/blob/master/src/searchd.cpp любая HandleMysqlXXX функция \ или ClientSession_c::Execute

tomatolog commented 1 year ago

I see the changes should be:

ba221400 commented 1 month ago

Is there any update on this effort? I missed this and opened #2483. As I mentioned there, we use ADOdb with PHP to parameterize our statements, and use the mysqli driver underneath.

This looks something like this:

$sql = $db->Prepare("SELECT * FROM manticore_table WHERE match(?)");

$params = array("My Search Term");

$result = $db->execute($sql, $params); // can also do $db->getRow($sql, $params) or $db->getArray($sql, $params)

ADOdb handles quoting so we don't typically have to do any additional sanitization/escaping for it. Since Manticore has a handful of characters that need escaped, I am not certain if mysql/ADOdb would completely handle this. I haven't looked too closely at the code, but believe ADOdb essentially runs their qStr() function on parameterized statements.

Links: https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:prepare https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:execute https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:getrow https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:getarray https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:qstr

sanikolaev commented 1 month ago

I haven't heard from @UtfCube who was going to make a pull request with this change since May. I'll discuss it with the core team to estimate this issue.