phpClickHouse icon indicating copy to clipboard operation
phpClickHouse copied to clipboard

How to prevent the SQL Injection with this lib

Open apausepi opened this issue 4 years ago • 2 comments
trafficstars

Are there a solution like PDO::setParameter(..) ?

apausepi avatar Feb 02 '21 15:02 apausepi

I have investigated that for https://github.com/simPod/PhpClickHouseClient and I recommend subscribing https://github.com/ClickHouse/ClickHouse/issues/8842

simPod avatar Jan 01 '22 19:01 simPod

I`m try implement

curl -X POST -F 'query=select {p1:UInt8} + {p2:UInt8}' -F "param_p1=3" -F "param_p2=4" 'http://default:default@localhost:8123/'
7

isublimity avatar Jun 09 '22 19:06 isublimity

Was this implemented? While I can use {x} within a query, it doesn't appear to get escaped - and just a dumb string replacement happens, leading to sqli vulns

I'm doing

$db->select('select * from test where ID={ID}', ['ID' => 1]);

devicenull avatar Jan 19 '23 21:01 devicenull

I would also like to know if there are plans to implement it.

donatascn avatar Mar 10 '23 14:03 donatascn

If someone is ready to test the implementation in dev23

https://github.com/smi2/phpClickHouse/blob/dev23/tests/BindingsPostTest.php#L18

if the request contains {\w+:\w+}it will be passed to the post

isublimity avatar Mar 10 '23 16:03 isublimity

Code support old binds without typeCast and new

$db->select('select * from test where ID={ID}', ['ID' => 1]);


$db->select('select * from test where ID={ID:UInt8}', ['ID' => 1]);

isublimity avatar Mar 10 '23 16:03 isublimity

I will not be able to conduct full tests before publishing to the master branch. All phpUnitTest - OK

I can try push master "as it is now" and see what happens -)))

isublimity avatar Mar 10 '23 16:03 isublimity

After some testing found an issue with the expression {\w+:\w+}. It will fail with array type:

select {numbers_array:Array(UInt64)};

Otherwise, it seems to be working just fine.

antanasja avatar May 03 '23 14:05 antanasja

Added support for arrays.

antanasja avatar May 24 '23 13:05 antanasja

@isublimity Can we get a new release regarding this?

antanasja avatar May 25 '23 06:05 antanasja

pub 1.5.1

isublimity avatar May 25 '23 07:05 isublimity