diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java index bc3f4e482c..d3c44bb7cf 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java @@ -339,8 +339,9 @@ public class ApexCRUDViolationRule extends AbstractApexRule { private boolean isWithSecurityEnforced(final AbstractApexNode node){ if(node instanceof ASTSoqlExpression){ - String pattern = ".*\\b[Ww][Ii][Tt][Hh] [Ss][Ee][Cc][Uu][Rr][Ii][Tt][Yy]_[Ee][Nn][Ff][Oo][Rr][Cc][Ee][Dd]\\b.*"; - return ((ASTSoqlExpression) node).getQuery().matches(pattern); + String pattern = "(?i).*[^']\\s*WITH SECURITY_ENFORCED\\s*[^']*"; + String query = ((ASTSoqlExpression) node).getQuery(); + return query.matches(pattern); } return false; } @@ -515,7 +516,6 @@ public class ApexCRUDViolationRule extends AbstractApexRule { if (!typeToDMLOperationMapping.containsKey(typeCheck)) { if (!isProperESAPICheckForDML(typeCheck, crudMethod)) { if(!isWithSecurityEnforced(node)) { - addViolation(data, node); } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml index 15ba41f064..416398315e 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml @@ -276,7 +276,7 @@ public class Foo { - Accepts Closure SECURITY ENFORCED 2 + Accepts Closure SECURITY ENFORCED in a List 0 - Accepts Closure SECURITY ENFORCED 3 + Accepts Closure SECURITY ENFORCED with Case Insensitivity 0 + + Accepts Closure SECURITY ENFORCED Not Secured + 1 + + + + Accepts Closure SECURITY ENFORCED Secured + 0 + + Proper accessibility CRUD,FLS