在sql查询中,单击“内部安全”方法以筛选包括帐户id或用户id的内容

fdbelqdn  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(1)|浏览(231)

我想让我们的用户通过我们的api文件的数据。我们想申请 accountId 以及where条件下的所有过滤器(由用户提供)。我不知道我们的用户如何操纵帐户id。什么是安全的应用过滤器连同帐户id?
我们想避免任何 sql injection 所有人都能得到结果 accountIds . 我们正在考虑写子查询。我们真的怀疑这些表演。
普通查询:

select any(accountId), appName, avg(duration) from performance_table where
accountId = '500' and  eventDateTime >= now() - 30 * 60 and env = "production"
group by appName order by appName limit 10

使用子查询:
子查询1:

select any(accountId), appName, avg(duration) from (select * from  
performance_table where
accountId = '500' and  eventDateTime >= now() - 30 * 60) where env = "production"
group by appName order by appName limit 10

子查询2:

select * from (select any(accountId), appName, avg(duration) from performance_table 
where accountId = '500' and eventDateTime >= now() - 30 * 60
where env = "production" group by appName order by appName limit 10) where accountId = '500'

你能建议一下安全的方法吗?

9lowa7mx

9lowa7mx1#

如果我理解正确,你可以通过预先准备 accountId = '500' 到where子句并生成

....   where accountId = '500'  and ( <user predicates> )

相关问题