From ba1222083d669b73defdb0a0ec1709dc1194e3f5 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 30 Nov 2016 16:11:19 -0800 Subject: [PATCH] Adding detection nested binary expressions --- .../security/ApexXSSFromURLParamRule.java | 5 ++ .../rule/security/xml/ApexXSSFromURLParam.xml | 68 ++++++++++++------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java index de46e70bf5..f4102789b6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java @@ -209,6 +209,11 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule { } private void processBinaryExpression(AbstractApexNode node, Object data) { + ASTBinaryExpression nestedBinaryExpression = node.getFirstChildOfType(ASTBinaryExpression.class); + if (nestedBinaryExpression != null) { + processBinaryExpression(nestedBinaryExpression, data); + } + ASTMethodCallExpression methodCallAssignment = node.getFirstChildOfType(ASTMethodCallExpression.class); if (methodCallAssignment != null) { processInlineMethodCalls(methodCallAssignment, data, true); diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexXSSFromURLParam.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexXSSFromURLParam.xml index 5328e63bec..aa38686fb1 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexXSSFromURLParam.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexXSSFromURLParam.xml @@ -13,8 +13,8 @@ public class Foo { } ]]> - - + + URL parameter in return statement concatenation 1 - URL parameter used without being escaped in return statement + URL parameter used without being escaped in return + statement 1 - URL parameter used without being escaped in return statement concatenation + URL parameter used without being escaped in return + statement concatenation 1 - + + URL parameter used without being escaped in return + statement concatenation 2 + 1 + + + + URL parameter used without being escaped 1 1 - - - + + + URL parameter passed to a function 1 - - + + Safe URL parameter passed to a function 0 @@ -190,10 +206,11 @@ public class Foo { } } ]]> - - + + - URL parameter passed to a function with variable declaration + URL parameter passed to a function with variable + declaration 1 - + - Safe URL parameter passed to a function with variable declaration + Safe URL parameter passed to a function with variable + declaration 0 - - - + + + URL parameter concatenated with variable 1 @@ -227,8 +245,8 @@ public class Foo { } } ]]> - - + + Safe URL parameter concatenated with variable @@ -240,8 +258,8 @@ public class Foo { } } ]]> - - + + URL parameter type casting is a safety check 0 @@ -255,7 +273,7 @@ public class Foo { } ]]> - + URL parameter method passing 1 @@ -268,8 +286,8 @@ public class Foo { } } ]]> - - + +