|
Here is the simplified version of the code I'm working on: import java.lang.Runtime;
public class Main {
private static String unused = "";
public static void source(String userInput) {
this.unused = userInput;
}
private void execUnused() {
Runtime.getRuntime().exec(this.unused);
}
}and the query I'm using to track /**
* @kind path-problem
*/
import java
import semmle.code.java.dataflow.FlowSources
import semmle.code.java.security.CommandLineQuery
class SourceMethod extends Method {
SourceMethod() { this.getName() = "source" }
}
module MyConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source.(DataFlow::InstanceParameterNode).getCallable() instanceof SourceMethod or
source.asParameter().getCallable() instanceof SourceMethod
}
predicate isSink(DataFlow::Node sink) {
exists(Call c |
c.getCallee().hasQualifiedName("java.lang", "Runtime", "exec") and
(
sink.asExpr() = c.getAnArgument() or
sink.asExpr() = c.getQualifier()
)
)
}
}
module MyFlow = TaintTracking::Global<MyConfig>;
import MyFlow::PathGraph
from MyFlow::PathNode source, MyFlow::PathNode sink
where MyFlow::flowPath(source, sink)
select sink.getNode(), source, sink, "sink: $@", source.getNode(), sink.toStringWithContext()I expect the query to return an empty result, since the tainted input does not reach the sink from Is there a way to prevent this and restrict the results to code reachable from the source method? |
Answered by
ginsbach
Aug 16, 2024
Replies: 2 comments 2 replies
|
Thank you for the question! |
0 replies
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

You could use the Java call graph classes to enforce that restriction.
However, note that there might be good reasons for the existing behaviour. Consider the following example: