Replies: 2 comments 1 reply
-
| It is perhaps a bit unusual to have an |
Beta Was this translation helpful? Give feedback.
-
| Hi. I am not aware of any real life vulnerabilities that exploit this exact behaviour. However, I do think that there exist real life scenarios where tracking these implicit string concatenations is helpful. For example, assume a java application which has a deserialization vulnerability and a dependency on jackson-databind. It is known, that calling Thats where the snippet I posted above comes into play. I was looking for a way to reach the But I also want to add that this is not restricted to implicit ".toString". For example, passing an object of a class that implements "java.lang.Comparable" to "java.util.TreeSet.add()" will trigger the "compareTo" function of the object. This is not tracked (and I think similar points can be made for .equals, .hashCode and other methods): import java.io.IOException; import java.util.*; public class TestCompare { public static class MyList implements Comparable<MyList> { private String s; public void setS(String s) { this.s = s; } @Override public int compareTo(MyList myList) { try{ Runtime.getRuntime().exec(myList.s); } catch (Exception e) { // throw new RuntimeException(e); } return 0; } } public static void main(String[] args) { MyList list1 = new MyList(); list1.setS(args[0]); MyList list2 = new MyList(); list1.compareTo(list2); Set<MyList> l = new TreeSet<>(); l.add(list1); l.add(list2); } }/** * @kind path-problem */ import java import semmle.code.java.dataflow.FlowSources module Config implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { source.asParameter().getCallable().hasName("main") and source.getEnclosingCallable().getDeclaringType().hasName("TestCompare") } DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext } predicate isSink(DataFlow::Node sink) { any() } } module Flow = TaintTracking::Global<Config>; import Flow::PathGraph from Flow::PathNode source, Flow::PathNode sink where Flow::flowPath(source, sink) select sink.getNode(), source, sink, "sink: $@", source.getNode(), sink.toStringWithContext() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Given the following code:
The following query finds the
execsink throughlist.toString();, but not viaString x = list + "";orjava.lang.String.valueOf(list);, which both trigger thetoStringmethod indirectly:Is this intended? Are there methods to modify this behaviour, without having to change the internal implementation?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions