mongoDB注入

发布于 2024-10-02 12:36:39 字数 48 浏览 0 评论 0原文

Java 中是否有通用模式来避免 mongoDB 注入攻击?

谢谢

is there a common pattern in Java to avoid mongoDB injection attacks?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哽咽笑 2024-10-09 12:36:39

使用受支持的驱动程序之一。不要将字符串反序列化为 JSON 并将它们作为查询传递,例如不要这样做(在 Ruby 中):

collection.send(query_type, JSON.parse(parameters))

其中 query_typeparameters 是来自表单的字符串。不过,你必须愚蠢到犯法才能这样做。

由于没有这样的查询语言,因此没有相同的注入空间。 SQL 注入攻击可能发生的部分原因是要采取的操作(SELECTUPDATEDELETE 等)是查询字符串。 MongoDB 和许多其他较新的数据库不是这样工作的,相反,操作是 API 的一部分。 SQL 驱动程序仅具有 query,在某些情况下具有 exec,而 MongoDB 具有 findupdateinsert删除

Use one of the supported drivers. Don't deserialize strings as JSON and pass them as queries, e.g. dont' do this (in Ruby):

collection.send(query_type, JSON.parse(parameters))

where query_type and parameters are strings coming from a form. You would have to be criminally stupid to do this though.

Since there's no query language as such there's not the same room for injection. Part of the reason that SQL injection attacks are possible is that the action to take (SELECT, UPDATE, DELETE, etc.) is part of the query string. MongoDB, and many other newer databases, don't work like that, instead the action is a part of the API. Where SQL drivers only have query and in some cases exec, MongoDB has find, update, insert and remove.

陌上青苔 2024-10-09 12:36:39

您可以在 where 子句中使用 Javascript 构建 MongoDB 查询,并且可以在此处进行注入。这里解释如何防止这种情况: https://docs.mongodb.com/manual/faq/fundamentals/#how-does-mongodb-address-sql-or-query-injection

You can build MongoDB querys with Javascript in the where clause and here injection can happen. Here explanation how to prevent this: https://docs.mongodb.com/manual/faq/fundamentals/#how-does-mongodb-address-sql-or-query-injection

情栀口红 2024-10-09 12:36:39

大多数驱动程序都是在您将查询构造为 BSON 文档的语言表示形式的情况下进行设置的。您打算在哪些语言中使用 mongo?

Most of the drivers are setup where you construct queries as the languages representation of BSON documents. What languages do you intend to use mongo in?

2024-10-09 12:36:39

是的,通过使用正则表达式搜索。
例如:假设您确实通过用户名进行检查并且没有使用 EQ 操作。
例如,如果我通过 [az],我将绕过您的登录操作:)。

但无论如何,这在很大程度上取决于解决方案中如何实现事物的逻辑。

yes there is, by using regex search.
Ex: lets say you do check by username and you are not using EQ op.
If i pass [a-z] for example i will bypass your login action :).

But anyway, it very much depends on the logic of how things are implemented in the solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文