0

我在 Java EE 中使用 MongoDB 和 Morphia Object Document Mapper。

@Override
public void removeTrustedDevice(String username, String cookieValue) {
    MongoConnection conn = MongoConnection.getInstance();
    TrustedDeviceDao dao = new TrustedDeviceDao(conn.getDatastore());
    Query<TrustedDevice> query = dao.createQuery();
    query.and(
            query.criteria("username").equal(username),
            query.criteria("cookieValue").equal(cookieValue)
    );

    List<TrustedDevice> deviceList = query.asList();

    if (deviceList != null && !deviceList.isEmpty()) {
        dao.delete(deviceList.get(0));
    }
}

No SQL注入有没有可能?如果是,请给我建议或示例以进行预防。

4

1 回答 1

0

我不会说这种攻击的可能性是0,因为黑客是聪明、坚定的类型,但我会说你不必过分担心它,而且在我与 MongoDB 合作的所有岁月中,我从来没有听说过这样的攻击。

SQL 注入攻击的部分工作原理是利用 SQL 查询在服务器端解析和评估的事实。DocumentMongo 查询已经以格式到达服务器。MongoDB 查询不像 SQL 那样支持注释,因此攻击向量不可用。因为查询已经是定义明确的结构化格式,并且没有在服务器上解析,所以要发起类似的攻击要困难得多。

于 2018-12-06T13:31:37.837 回答