forked from phoedos/pmd
Improving open redirect detection for strings prefixed with /
This commit is contained in:

committed by
Juan Martín Sotuyo Dodero

parent
c9514e563a
commit
9c85a78884
@@ -64,15 +64,33 @@ public class ApexOpenRedirectRule extends AbstractApexRule {
|
||||
}
|
||||
|
||||
private void findSafeLiterals(AbstractApexNode<?> node) {
|
||||
ASTBinaryExpression binaryExp = node.getFirstChildOfType(ASTBinaryExpression.class);
|
||||
if (binaryExp != null) {
|
||||
findSafeLiterals(binaryExp);
|
||||
}
|
||||
|
||||
ASTLiteralExpression literal = node.getFirstChildOfType(ASTLiteralExpression.class);
|
||||
if (literal != null) {
|
||||
ASTVariableExpression variable = node.getFirstChildOfType(ASTVariableExpression.class);
|
||||
if (variable != null) {
|
||||
listOfStringLiteralVariables.add(Helper.getFQVariableName(variable));
|
||||
int index = literal.jjtGetChildIndex();
|
||||
if (index == 0) {
|
||||
if (node instanceof ASTVariableDeclaration) {
|
||||
addVariable(node);
|
||||
} else {
|
||||
ASTVariableDeclaration parent = node.getFirstParentOfType(ASTVariableDeclaration.class);
|
||||
addVariable(parent);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addVariable(AbstractApexNode<?> node) {
|
||||
ASTVariableExpression variable = node.getFirstChildOfType(ASTVariableExpression.class);
|
||||
if (variable != null) {
|
||||
listOfStringLiteralVariables.add(Helper.getFQVariableName(variable));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses all new declarations to find PageReferences
|
||||
*
|
||||
|
@@ -136,8 +136,39 @@ public class Foo {
|
||||
static PageReference redirect() {
|
||||
return pr;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Unsafe pageReference object</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
|
||||
static PageReference redirect(String otherStuff) {
|
||||
String test1 = otherStuff + '/';
|
||||
PageReference pr = new PageReference(test1);
|
||||
return pr;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Safe pageReference object</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
|
||||
static PageReference redirect(String otherStuff) {
|
||||
String test1 = '/' + otherStuff;
|
||||
PageReference pr = new PageReference(test1);
|
||||
return pr;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user