gpt4 book ai didi

kotlin - 二阶 SOQL SOSL 注入(inject) SFDC

转载 作者:行者123 更新时间:2023-12-02 13:16:27 27 4
gpt4 key购买 nike

我在 Checkmarx 中遇到错误。

Method abortJob at line 209 of XXX/classes/Monitoring.cls gets user inputfrom the select element.
This element’s value then flows through the code without being properly sanitized or validated, and is eventually used in a database query in method jobAbortRem at line 209 of XXX/classes/Monitoring.cls.
This may enable anSOQL Injection attack.

              Source                                Destination   
File XXXX/classes/Monitoring.cls XXXX/classes/Monitoring.cls
Line 212 217
Object select select
public static void abortJob() //line no. 209
{
list<CronTrigger> detailId=[select id FROM CronTrigger
where (CronJobDetail.Name='myJobName') AND NextFireTime = null]; //line 212

if (detailId.size() > 0)
{
Id jobId = [SELECT Id from CronTrigger WHERE id = :detailId].get(0).Id; //and line 217
System.abortJob(jobId);
Monitoring.scheduleJob();
}
}
帮助我解决这个问题,我怎样才能通过 Checkmarx 审查。
谢谢

最佳答案

使用 escapeSingleQuotes 方法清理 detailId 的每个元素(我建议重命名这个)集合

public static void abortJob() { 
list<CronTrigger> detailId=[select id FROM CronTrigger where (CronJobDetail.Name='myJobName' ) AND NextFireTime =null];
Id jobId ;
for (CronTrigger currentCron : detailId) {
jobId = String.escapeSingleQuotes(currentCron.Id);
}
if (jobId !=null) {
System.abortJob(jobId);
Monitoring.scheduleJob();
}
}
这是 Salesforce Secure Coding有用的引用
您可能还想尝试这种类型的循环来处理查询结果的每个项目
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_SOQL.htm

关于kotlin - 二阶 SOQL SOSL 注入(inject) SFDC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63517357/

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