我正在尝试查找有关 Spring Security JPA 的信息,以及是否像 .save()
这样的方法受到了 sql 注入(inject)的保护。
例如,我有一个对象Customer.
,我想将它保存到我的数据库中。
我正在使用 CustomerRepository Spring 实现对该实体进行操作。
客户的构造函数正在使用来自用户的参数。一切准备就绪后,我将调用 .save()
。这对 sql 注入(inject)安全吗?还是我应该先进行检查?
最佳答案
.save()
是安全的,只有使用 native 查询容易受到攻击。
List results = entityManager.createNativeQuery("Select * from Customer where name = " + name).getResultList();
如果您使用参数,您也可以使 native 查询安全。
Query sqlQuery = entityManager.createNativeQuery("Select * from Customer where name = ?", Customer.class);
List results = sqlQuery.setParameter(1, "John Doe").getResultList();
关于database - Spring Data JPA 对 SQL 注入(inject)是否安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41661193/