我是新手-通过将 spring 与 MongoDB 结合使用。
我正在使用一个使用 MongoOperations 对象的 Dao 模式。
因为我在 RDBMS 和 JPA 方面有很多经验,所以我们通常使用 setParameter,它也负责转义和避免 SQL 注入(inject)。
我在想MongoDB Spring 有没有这样的想法。我找不到它,但我可能会遗漏一些东西。我不得不说我仍然不确定使用 Mongo 是否存在 SQL 注入(inject)风险。
另外,有没有办法在 MongoDB 中创建命名查询?
谢谢大家
最佳答案
NOSQL 注入(inject)与 SQL 注入(inject)非常相似。
特殊字符不同但概念相同:用户可以控制/修改/破坏请求。
Yet these databases are still potentially vulnerable to injection attacks, even if they aren't using the traditional SQL syntax. Because these NoSQL injection attacks may execute within a procedural language , rather than in the declarative SQL language, the potential impacts are greater than traditional SQL injection
有一种方法可以验证,here is an OWASP page那会帮助你测试。
最基本的是验证您的请求是否正确地转义了 ' "\; { }
甚至更多。
似乎 spring data mongodb 正确地转义了那些,但我不知道它是否完全安全。
关于命名查询,我认为this answer是正确的,它们不存在,但如果您有存储库,您仍然有一个 @Query
注释。
因为您正在使用自定义存储库并不意味着您也不能使用存储库接口(interface),Spring 数据允许您在不实现 repostiroy 的情况下实现它,see here .
关于spring for mongodb转义参数以避免SQL注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27994063/