gpt4 book ai didi

security - 用于 Google App Engine 的 JDO : escaping quotes

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:56 24 4
gpt4 key购买 nike

如何在 JDO (Google App Engine) 中转义查询参数?

例如,如果变量名称可能包含不安全的字符作为单引号 ('),我如何使下一个片段安全

PersistenceManager pm = ...;
String query = "select from Person where name='"+name+"'";
List<Shortened> shortened = (List<Shortened>) pm.newQuery(query).execute();

最佳答案

改用查询参数,这比在查询本身中包含值要安全得多。这是 GAE 文档中的示例:

Query query = pm.newQuery("select from Employee " +
"where lastName == lastNameParam " +
"order by hireDate desc " +
"parameters String lastNameParam");

List<Employee> results = (List<Employee>) query.execute("Smith");

关于security - 用于 Google App Engine 的 JDO : escaping quotes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1496996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com