Skip to content

Commit d5f0a05

Browse files
authored
Apply batched suggestions from code review
Co-authored-by: Owen Mansel-Chan <62447351+owen-mc@users.noreply.github.com>
1 parent 0eb81a5 commit d5f0a05

3 files changed

Lines changed: 57 additions & 31 deletions

File tree

‎java/ql/lib/ext/reactor.core.publisher.model.json‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
"extensible": "summaryModel"
77
},
88
"data": [
9-
["reactor.core.publisher", "Mono", true, "justOrEmpty", "", "", "Argument[0]", "Argument[this]", "taint", "manual"],
10-
["reactor.core.publisher", "Mono", true, "just", "", "", "Argument[0]", "Argument[this]", "taint", "manual"],
11-
["reactor.core.publisher", "Mono", true, "flatMap", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "taint", "manual"],
12-
["reactor.core.publisher", "Mono", true, "map", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "taint", "manual"],
13-
["reactor.core.publisher", "Mono", true, "mapNotNull", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "taint", "manual"]
9+
["reactor.core.publisher", "Mono", true, "justOrEmpty", "(Object)", "", "Argument[0]", "ReturnValue.Element", "value", "manual"],
10+
["reactor.core.publisher", "Mono", true, "justOrEmpty", "(Optional)", "", "Argument[0].Element", "ReturnValue.Element", "value", "manual"],
11+
["reactor.core.publisher", "Mono", true, "just", "", "", "Argument[0]", "ReturnValue.Element", "value", "manual"],
12+
["reactor.core.publisher", "Mono", true, "flatMap", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "value", "manual"],
13+
["reactor.core.publisher", "Mono", true, "flatMap", "", "", "Argument[0].ReturnValue.Element", "ReturnValue.Element", "value", "manual"],
14+
["reactor.core.publisher", "Mono", true, "map", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "value", "manual"],
15+
["reactor.core.publisher", "Mono", true, "map", "", "", "Argument[0].ReturnValue", "ReturnValue.Element", "value", "manual"],
16+
["reactor.core.publisher", "Mono", true, "mapNotNull", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "value", "manual"],
17+
["reactor.core.publisher", "Mono", true, "mapNotNull", "", "", "Argument[0].ReturnValue", "ReturnValue.Element", "value", "manual"]
1418
]
1519
}
1620
]

‎java/ql/test/library-tests/frameworks/reactor-core/Test.java‎

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,51 @@ String taint() {
1111

1212
void testJust() {
1313
Mono<String> unsafe = Mono.just(taint());
14-
sink(unsafe); // $ hasTaintFlow
14+
unsafe.map(value -> {
15+
sink(value); // $ hasValueFlow
16+
return value;
17+
});
1518
Mono<String> safe = Mono.just("safe");
16-
sink(safe); // no taint flow
19+
safe.map(value -> {
20+
sink(value); // no taint flow
21+
return value;
22+
});
1723
}
1824

1925
void testJustOrEmpty() {
2026
Mono<String> unsafe = Mono.justOrEmpty(taint());
21-
sink(unsafe); // $ hasTaintFlow
27+
unsafe.map(value -> {
28+
sink(value); // $ hasValueFlow
29+
return value;
30+
});
2231
Mono<String> safe = Mono.justOrEmpty("safe");
23-
sink(safe); // no taint flow
32+
safe.map(value -> {
33+
sink(value); // no taint flow
34+
return value;
35+
});
2436
}
2537

2638
void testJustOrEmptyOptional() {
2739
Mono<String> unsafe = Mono.justOrEmpty(Optional.of(taint()));
28-
sink(unsafe); // $ hasTaintFlow
40+
unsafe.map(value -> {
41+
sink(value); // $ hasValueFlow
42+
return value;
43+
});
2944
Mono<String> safe = Mono.justOrEmpty(Optional.of("safe"));
30-
sink(safe); // no taint flow
45+
safe.map(value -> {
46+
sink(value); // no taint flow
47+
return value;
48+
});
3149
Mono<String> empty = Mono.justOrEmpty(Optional.<String>empty());
32-
sink(empty); // no taint flow
50+
empty.map(value -> {
51+
sink(value); // no taint flow
52+
return value;
53+
});
3354
}
3455

3556
void testFlatMap() {
3657
Mono.just(taint()).flatMap(value -> {
37-
sink(value); // $ hasTaintFlow
58+
sink(value); // $ hasValueFlow
3859
return Mono.just("safe");
3960
});
4061
Mono.just("safe").flatMap(value -> {
@@ -45,7 +66,7 @@ void testFlatMap() {
4566

4667
void testMap() {
4768
Mono.just(taint()).map(value -> {
48-
sink(value); // $ hasTaintFlow
69+
sink(value); // $ hasValueFlow
4970
return "safe";
5071
});
5172
Mono.just("safe").map(value -> {
@@ -56,12 +77,27 @@ void testMap() {
5677

5778
void testMapNotNull() {
5879
Mono.just(taint()).mapNotNull(value -> {
59-
sink(value); // $ hasTaintFlow
80+
sink(value); // $ hasValueFlow
6081
return "safe";
6182
});
6283
Mono.just("safe").mapNotNull(value -> {
6384
sink(value); // no taint flow
6485
return "safe";
6586
});
6687
}
88+
89+
void testNestedValues() {
90+
Mono.just(Optional.of(taint())).flatMap(value -> {
91+
sink(value.get()); // $ hasValueFlow
92+
return Mono.just("safe");
93+
});
94+
Mono.just(Optional.of(taint())).map(value -> {
95+
sink(value.get()); // $ hasValueFlow
96+
return "safe";
97+
});
98+
Mono.just(Optional.of(taint())).mapNotNull(value -> {
99+
sink(value.get()); // $ hasValueFlow
100+
return "safe";
101+
});
102+
}
67103
}
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
import java
2-
import semmle.code.java.dataflow.TaintTracking
3-
import semmle.code.java.dataflow.FlowSources
42
import utils.test.InlineFlowTest
5-
6-
module Config implements DataFlow::ConfigSig {
7-
predicate isSource(DataFlow::Node n) {
8-
n.asExpr().(MethodCall).getMethod().hasName("taint")
9-
or
10-
n instanceof ActiveThreatModelSource
11-
}
12-
13-
predicate isSink(DataFlow::Node n) {
14-
exists(MethodCall ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
15-
}
16-
}
17-
18-
import TaintFlowTest<Config>
3+
import DefaultFlowTest
4+
import TaintFlow::PathGraph

0 commit comments

Comments
 (0)