The CodeQL query raises false positive issues when finding a path from a user-invoked public function A to a function B called inside A #12497
-
Hi, everyone. I want to find a path from a public API //A->call B or A->call others->call B
public A(source){
B(); // or indirectly call B
} But CodeQL raises some false positive issues in the following example: private function hidden(int fakeSource)
{
test = A(fakeSource);
B(test);
}
public function A(int source)
{
return;
} As shown in the example, there does not exist a path starting from a user-invoked However, CodeQL considers a possible path starting from the So the tainted path shown by CodeQL is (un-displayed hidden)->A->return->B, which is not the pattern indicating B is directly or indirectly called inside A. Is there any idea can help? For example, I am trying to sanitize the taint tracking of a specific return statement at a function where the taint tracking process starts, but failed to do so. The related ql code is presented as below: /**
* @kind path-problem
*/
import java
import semmle.code.java.dataflow.TaintTracking
import semmle.code.java.dataflow.TaintTracking2
import DataFlow2::PathGraph
import semmle.code.java.dataflow.DataFlow
class TestTaint extends TaintTracking2::Configuration {
TestTaint() { this = "TestTaint" }
override predicate isSource(DataFlow2::Node source) {
exists(Method method | method.getAParameter() = source.asParameter() and method.isPublic())
}
override predicate isSink(DataFlow2::Node sink) {
exists(MethodAccess call | sink.asExpr() = call.getAnArgument())
}
}
from TestTaint config1, DataFlow2::PathNode source1, DataFlow2::PathNode sink1
where config1.hasFlowPath(source1, sink1)
select source1, source1, sink1, "123" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I can't reproduce this-- Your example appears to be a mixture of Java and JavaScript syntax, but given you import public class Test {
private void hidden(int nonSource)
{
int test = a(nonSource);
b(test);
}
public int a(int source) { return 0; }
private void b(int source) { }
} With this input and the CodeQL you posted, I get no results, as expected. |
Beta Was this translation helpful? Give feedback.
-
It sounds like what you want is not having flow out of a method containing a source to an arbitrary call site. In that case, you can use a Try adding this to your configuration: override DataFlow::FlowFeature getAFeature() {
result instanceof DataFlow::FeatureHasSourceCallContext
} |
Beta Was this translation helpful? Give feedback.
It sounds like what you want is not having flow out of a method containing a source to an arbitrary call site. In that case, you can use a
FlowFeature
to tell the dataflow configuration that you don't want it to assume arbitrary call contexts when reaching areturn
statement from a source.Try adding this to your configuration: