signoz icon indicating copy to clipboard operation
signoz copied to clipboard

Move db calls to prepared statements with context

Open ankitnayan opened this issue 3 years ago • 7 comments

Move all db calls to prepared statements and specifically with context if possible to make signoz more secure from sql injections. A query should not be a string prepared from fmt.sprintf(...) if it has args to pass. We should try to avoid string formatting for args.

ankitnayan avatar Jul 04 '22 04:07 ankitnayan

Hi @ankitnayan Please assign this issue to me, I will complete the query-service installation today and will start making the changes. Also since we go for the Prepared Statements, here we are only trying to address the insecurities that arise due to malicious SQL data literals.

jshiwam avatar Jul 04 '22 06:07 jshiwam

https://github.com/jshiwam/signoz/commit/f18be5c9f7e1699199861f3ca2b19a63e633ea3c

Hi @ankitnayan please check these comments. I have added them for some clarifications, as my understanding of the whole flow of the project might not be good enough. Please reply on those comments and point out if I have identified all the statments that need to be chagned. Thanks.

jshiwam avatar Jul 16 '22 08:07 jshiwam

@jshiwam I think you are going to the right direction. One suggestion is to apply changes to only a few APIs or maybe 1 single API to start with and get it merged and then keep on adding small PRs for a small set of each APIs.

@srikanthccv please have a look and guide if needed

ankitnayan avatar Jul 16 '22 08:07 ankitnayan

Sure Actually I have made change to one of the functions and it is working, the testing is also complete. I will remove the comments from those files and only keep that single change and make the first PR.

jshiwam avatar Jul 16 '22 10:07 jshiwam

Not fully addressed

srikanthccv avatar Aug 02 '22 07:08 srikanthccv

Thanks @srikanthccv will add the changes here.

jshiwam avatar Aug 02 '22 08:08 jshiwam

@srikanthccv @ankitnayan GetService queries clickhouse and we use the clickhouse-driver Conn in order to query the data there. I am not sure if they provide a way to use Prepare Statements. I am new to clickhouse so might be missing something. Please let me know if my observation is correct.

jshiwam avatar Aug 04 '22 06:08 jshiwam

Best regards, the issue is based on changing the calls to the databases by SPS?

Arcangellmar avatar Jun 08 '23 22:06 Arcangellmar

Hey @ankitnayan @srikanthccv do we have to migrate the db calls which directly call Exec without preparing the Query Like, the following? image

srikanth-iyengar avatar Nov 15 '23 16:11 srikanth-iyengar