Skip to content

Commit a0b7f26

Browse files
author
Benjamin Muskalla
committed
Only capture taint from own fields
Also exclude `Charset` as relevant taint-carrying type. This is generally what we want to lets us avoid tracking arguments that lead to FP.
1 parent 0234e77 commit a0b7f26

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

java/ql/src/utils/model-generator/CaptureSinkModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PropagateToSinkConfiguration extends TaintTracking::Configuration {
1616
PropagateToSinkConfiguration() { this = "parameters or flowing into sinks" }
1717

1818
override predicate isSource(DataFlow::Node source) {
19-
(source.asExpr() instanceof FieldAccess or source instanceof DataFlow::ParameterNode) and
19+
(source.asExpr().(FieldAccess).isOwnFieldAccess() or source instanceof DataFlow::ParameterNode) and
2020
source.getEnclosingCallable().isPublic() and
2121
exists(RefType t |
2222
t = source.getEnclosingCallable().getDeclaringType().getAnAncestor() and

java/ql/src/utils/model-generator/CaptureSummaryModels.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ class ParameterToReturnValueTaintConfig extends TaintTracking::Configuration {
190190
override predicate isSink(DataFlow::Node sink) { sink instanceof ReturnNodeExt }
191191

192192
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
193-
node2.asExpr().(ConstructorCall).getAnArgument() = node1.asExpr() and
194-
node1.asExpr().(Argument).getCall().getCallee().fromSource()
193+
node2.asExpr().(ConstructorCall).getAnArgument() = node1.asExpr()
195194
}
196195
}
197196

@@ -261,6 +260,7 @@ predicate isRelevantType(Type t) {
261260
not t instanceof PrimitiveType and
262261
not t instanceof BoxedType and
263262
not t.(RefType).getAnAncestor().hasQualifiedName("java.lang", "Number") and
263+
not t.(RefType).getAnAncestor().hasQualifiedName("java.nio.charset", "Charset") and
264264
(
265265
not t.(Array).getElementType() instanceof PrimitiveType or
266266
isPrimitiveTypeUsedForBulkData(t.(Array).getElementType())

java/ql/test/utils/model-generator/CaptureSummaryModels.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
| p;Pojo;false;getValue;();;Argument[-1];ReturnValue;taint |
4545
| p;Pojo;false;setValue;(String);;Argument[0];Argument[-1];taint |
4646
| p;PrivateFlowViaPublicInterface;true;createAnSPI;(File);;Argument[0];ReturnValue;taint |
47+
| p;PrivateFlowViaPublicInterface;true;createAnSPIWithoutTrackingFile;(File);;Argument[0];ReturnValue;taint |

java/ql/test/utils/model-generator/p/PrivateFlowViaPublicInterface.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
public class PrivateFlowViaPublicInterface {
99

10+
static class RandomPojo {
11+
public File someFile = new File("someFile");
12+
}
1013
public static interface SPI {
1114
OutputStream openStream() throws IOException;
15+
16+
default OutputStream openStreamNone() throws IOException {
17+
return null;
18+
};
1219
}
1320

1421
private static final class PrivateImplWithSink implements SPI {
@@ -25,9 +32,30 @@ public OutputStream openStream() throws IOException {
2532
}
2633

2734
}
35+
36+
private static final class PrivateImplWithRandomField implements SPI {
37+
38+
public PrivateImplWithRandomField(File file) {
39+
}
40+
41+
@Override
42+
public OutputStream openStream() throws IOException {
43+
return null;
44+
}
45+
46+
@Override
47+
public OutputStream openStreamNone() throws IOException {
48+
return new FileOutputStream(new RandomPojo().someFile);
49+
}
50+
51+
}
2852

2953
public static SPI createAnSPI(File file) {
3054
return new PrivateImplWithSink(file);
3155
}
56+
57+
public static SPI createAnSPIWithoutTrackingFile(File file) {
58+
return new PrivateImplWithRandomField(file);
59+
}
3260

3361
}

0 commit comments

Comments
 (0)