mongoDB注入
Java 中是否有通用模式来避免 mongoDB 注入攻击?
谢谢
is there a common pattern in Java to avoid mongoDB injection attacks?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Java 中是否有通用模式来避免 mongoDB 注入攻击?
谢谢
is there a common pattern in Java to avoid mongoDB injection attacks?
Thanks
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
使用受支持的驱动程序之一。不要将字符串反序列化为 JSON 并将它们作为查询传递,例如不要这样做(在 Ruby 中):
其中
query_type
和parameters
是来自表单的字符串。不过,你必须愚蠢到犯法才能这样做。由于没有这样的查询语言,因此没有相同的注入空间。 SQL 注入攻击可能发生的部分原因是要采取的操作(
SELECT
、UPDATE
、DELETE
等)是查询字符串。 MongoDB 和许多其他较新的数据库不是这样工作的,相反,操作是 API 的一部分。 SQL 驱动程序仅具有query
,在某些情况下具有exec
,而 MongoDB 具有find
、update
、insert
和删除
。Use one of the supported drivers. Don't deserialize strings as JSON and pass them as queries, e.g. dont' do this (in Ruby):
where
query_type
andparameters
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 havequery
and in some casesexec
, MongoDB hasfind
,update
,insert
andremove
.您可以在 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
大多数驱动程序都是在您将查询构造为 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?
是的,通过使用正则表达式搜索。
例如:假设您确实通过用户名进行检查并且没有使用 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.