gpt4 book ai didi

sql - 可以接受客户端 SQL 吗?如果可以,如何验证?

转载 作者:行者123 更新时间:2023-11-29 12:42:54 25 4
gpt4 key购买 nike

我有一个应用程序,我想在其中接受来自前端查询构建器 (http://querybuilder.js.org/) 的用户提供的 SQL 查询。该查询最终需要使其成为在 postgres 数据库中运行以返回数据子集的方式。

上面链接的查询生成器可以导出 SQL 或 mongo 查询。我想使用 mongo 查询是相对安全的,因为我可以简单地在服务器上添加它:

query.owner_of_document = userId

限制结果(到用户拥有的文档)。

而如果有人试图存储恶意的 SQL 字符串以供执行,则 SQL 语句可能会在注入(inject)攻击中被劫持。

直接接受来自客户端的 SQL 是不好的做法吗?如何确保提供的 SQL 是安全的?

谢谢!

最佳答案

为什么需要接受整个 SQL 语句?

您可以只接受参数然后运行预定义的查询吗?

SO 上有很多与 SQL 注入(inject)相关的问题/答案,使用参数是避免注入(inject)攻击的第一步,例如“Are Parameters really enough to prevent Sql injections?

但我认为this answer一个不同的问题总结得很好:

Don't try to do security yourself. Use whatever trusted, industry standard library there is available for what you're trying to do, rather than trying to do it yourself. Whatever assumptions you make about security, might be incorrect. As secure as your own approach may look ... there's a risk you're overlooking something and do you really want to take that chance when it comes to security?

关于sql - 可以接受客户端 SQL 吗?如果可以,如何验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40064879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com