【问题标题】:Safe way to filters including account id or user id in SQL query在 SQL 查询中过滤包括帐户 ID 或用户 ID 的安全方法
【发布时间】:2018-09-04 10:38:12
【问题描述】:

我想允许我们的用户通过我们的 API 来归档数据。我们想在 where 条件下应用 accountId 以及所有过滤器(由用户提供)。我不会让我们的用户操纵帐户 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'

您能建议安全的方法吗?

【问题讨论】:

  • 子查询在这里有什么帮助?
  • 您使用哪种语言/框架来实现您的 API?
  • Node.js 和 Go。截至目前,我们在 Node.js 中进行。
  • @sskoko 我认为子查询将被父查询过滤。我不确定。
  • select accountId, appName, avg(duration)...group by appName 在我看来是一个错误的查询。滥用 MySQL GROUP BY "feature"

标签: sql clickhouse


【解决方案1】:

如果我理解正确,您可以通过在 where 子句前面加上 accountId = '500' 并生成类似的东西来实现这一点

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

【讨论】:

    猜你喜欢
    • 2018-01-31
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多