Skip to content

Commit 7cfcbf6

Browse files
author
Stephan Brandauer
committed
Java: add extensible type to endpoint class in application mode
1 parent df2b313 commit 7cfcbf6

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ abstract private class ApplicationModeEndpoint extends TApplicationModeEndpoint
5151

5252
abstract DataFlow::Node asNode();
5353

54+
abstract string getExtensibleType();
55+
5456
abstract string toString();
5557
}
5658

@@ -69,6 +71,8 @@ class ExplicitArgument extends ApplicationModeEndpoint, TExplicitArgument {
6971

7072
override DataFlow::Node asNode() { result = arg }
7173

74+
override string getExtensibleType() { result = "sinkModel" }
75+
7276
override string toString() { result = arg.toString() }
7377
}
7478

@@ -86,6 +90,8 @@ class InstanceArgument extends ApplicationModeEndpoint, TInstanceArgument {
8690

8791
override DataFlow::Node asNode() { result = arg }
8892

93+
override string getExtensibleType() { result = "sinkModel" }
94+
8995
override string toString() { result = arg.toString() }
9096
}
9197

@@ -111,6 +117,8 @@ class ImplicitVarargsArray extends ApplicationModeEndpoint, TImplicitVarargsArra
111117

112118
override DataFlow::Node asNode() { result = vararg }
113119

120+
override string getExtensibleType() { result = "sinkModel" }
121+
114122
override string toString() { result = vararg.toString() }
115123
}
116124

@@ -168,9 +176,11 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
168176
)
169177
}
170178

179+
// XXX how to extend to support sources?
171180
additional predicate sinkSpec(
172181
Endpoint e, string package, string type, string name, string signature, string ext, string input
173182
) {
183+
e.getExtensibleType() = "sinkModel" and
174184
ApplicationModeGetCallable::getCallable(e).hasQualifiedName(package, type, name) and
175185
signature = ExternalFlow::paramsString(ApplicationModeGetCallable::getCallable(e)) and
176186
ext = "" and
@@ -407,7 +417,10 @@ private class CannotBeTaintedCharacteristic extends CharacteristicsImpl::LikelyN
407417
{
408418
CannotBeTaintedCharacteristic() { this = "cannot be tainted" }
409419

410-
override predicate appliesToEndpoint(Endpoint e) { not this.isKnownOutNodeForStep(e) }
420+
override predicate appliesToEndpoint(Endpoint e) {
421+
// XXX consider source candidate endpoints
422+
not this.isKnownOutNodeForStep(e)
423+
}
411424

412425
/**
413426
* Holds if the node `n` is known as the predecessor in a modeled flow step.

java/ql/automodel/src/AutomodelApplicationModeExtractCandidates.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ where
8585
sinkType, ", "
8686
)
8787
select endpoint.asNode(),
88-
message + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@.", //
88+
message + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@.", //
8989
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
9090
package, "package", //
9191
type, "type", //
@@ -94,4 +94,5 @@ select endpoint.asNode(),
9494
signature, "signature", //
9595
input, "input", //
9696
isVarargsArray, "isVarargsArray", //
97-
alreadyAiModeled, "alreadyAiModeled"
97+
alreadyAiModeled, "alreadyAiModeled", //
98+
endpoint.getExtensibleType().(DollarAtString), "extensibleType"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| Test.java:16:3:16:11 | reference | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:16:3:16:24 | set(...) | CallContext | file://java.util.concurrent.atomic:1:1:1:1 | java.util.concurrent.atomic | package | file://AtomicReference:1:1:1:1 | AtomicReference | type | file://false:1:1:1:1 | false | subtypes | file://set:1:1:1:1 | set | name | file://(String):1:1:1:1 | (String) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://false:1:1:1:1 | false | isVarargsArray | file://:1:1:1:1 | | alreadyAiModeled |
2-
| Test.java:21:3:21:10 | supplier | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:21:3:21:16 | get(...) | CallContext | file://java.util.function:1:1:1:1 | java.util.function | package | file://Supplier:1:1:1:1 | Supplier | type | file://true:1:1:1:1 | true | subtypes | file://get:1:1:1:1 | get | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://false:1:1:1:1 | false | isVarargsArray | file://:1:1:1:1 | | alreadyAiModeled |
3-
| Test.java:34:4:34:11 | openPath | command-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:33:10:35:3 | newInputStream(...) | CallContext | file://java.nio.file:1:1:1:1 | java.nio.file | package | file://Files:1:1:1:1 | Files | type | file://false:1:1:1:1 | false | subtypes | file://newInputStream:1:1:1:1 | newInputStream | name | file://(Path,OpenOption[]):1:1:1:1 | (Path,OpenOption[]) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://false:1:1:1:1 | false | isVarargsArray | file://ai-manual:1:1:1:1 | ai-manual | alreadyAiModeled |
4-
| Test.java:53:4:53:4 | o | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:51:3:56:3 | walk(...) | CallContext | file://java.nio.file:1:1:1:1 | java.nio.file | package | file://Files:1:1:1:1 | Files | type | file://false:1:1:1:1 | false | subtypes | file://walk:1:1:1:1 | walk | name | file://(Path,FileVisitOption[]):1:1:1:1 | (Path,FileVisitOption[]) | signature | file://Argument[1]:1:1:1:1 | Argument[1] | input | file://true:1:1:1:1 | true | isVarargsArray | file://:1:1:1:1 | | alreadyAiModeled |
1+
| Test.java:16:3:16:11 | reference | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:16:3:16:24 | set(...) | CallContext | file://java.util.concurrent.atomic:1:1:1:1 | java.util.concurrent.atomic | package | file://AtomicReference:1:1:1:1 | AtomicReference | type | file://false:1:1:1:1 | false | subtypes | file://set:1:1:1:1 | set | name | file://(String):1:1:1:1 | (String) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://false:1:1:1:1 | false | isVarargsArray | file://:1:1:1:1 | | alreadyAiModeled | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
2+
| Test.java:21:3:21:10 | supplier | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:21:3:21:16 | get(...) | CallContext | file://java.util.function:1:1:1:1 | java.util.function | package | file://Supplier:1:1:1:1 | Supplier | type | file://true:1:1:1:1 | true | subtypes | file://get:1:1:1:1 | get | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://false:1:1:1:1 | false | isVarargsArray | file://:1:1:1:1 | | alreadyAiModeled | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
3+
| Test.java:34:4:34:11 | openPath | command-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:33:10:35:3 | newInputStream(...) | CallContext | file://java.nio.file:1:1:1:1 | java.nio.file | package | file://Files:1:1:1:1 | Files | type | file://false:1:1:1:1 | false | subtypes | file://newInputStream:1:1:1:1 | newInputStream | name | file://(Path,OpenOption[]):1:1:1:1 | (Path,OpenOption[]) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://false:1:1:1:1 | false | isVarargsArray | file://ai-manual:1:1:1:1 | ai-manual | alreadyAiModeled | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
4+
| Test.java:53:4:53:4 | o | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:51:3:56:3 | walk(...) | CallContext | file://java.nio.file:1:1:1:1 | java.nio.file | package | file://Files:1:1:1:1 | Files | type | file://false:1:1:1:1 | false | subtypes | file://walk:1:1:1:1 | walk | name | file://(Path,FileVisitOption[]):1:1:1:1 | (Path,FileVisitOption[]) | signature | file://Argument[1]:1:1:1:1 | Argument[1] | input | file://true:1:1:1:1 | true | isVarargsArray | file://:1:1:1:1 | | alreadyAiModeled | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |

0 commit comments

Comments
 (0)