Skip to content

Commit 8614d7b

Browse files
author
Max Schaefer
committed
Address review feedback.
1 parent 90a4552 commit 8614d7b

7 files changed

+44
-41
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

-12
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,6 @@ abstract private class ApplicationModeEndpoint extends TApplicationModeEndpoint
9393
else none() // if both exist, it would be a summaryModel (not yet supported)
9494
}
9595

96-
/**
97-
* Gets a potential type of this endpoint to make sure that sources are
98-
* associated with source types and sinks with sink types.
99-
*/
100-
AutomodelEndpointTypes::EndpointType getAPotentialType() {
101-
this.getExtensibleType() = "sourceModel" and
102-
result instanceof AutomodelEndpointTypes::SourceType
103-
or
104-
this.getExtensibleType() = "sinkModel" and
105-
result instanceof AutomodelEndpointTypes::SinkType
106-
}
107-
10896
abstract string toString();
10997
}
11098

java/ql/automodel/src/AutomodelApplicationModeExtractNegativeExamples.ql

+11-5
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,28 @@ predicate candidate(
4545
string type, string subtypes, string name, string signature, string input, string output,
4646
string isVarargsArray, string extensibleType
4747
) {
48-
// the node is know not to be an endpoint of any appropriate type
49-
forall(EndpointType tp | tp = endpoint.getAPotentialType() |
48+
// the node is known not to be an endpoint of any appropriate type
49+
forall(EndpointType tp | tp = CharacteristicsImpl::getAPotentialType(endpoint) |
5050
characteristic.hasImplications(tp, false, _)
5151
) and
5252
// the lowest confidence across all endpoint types should be at least highConfidence
53-
confidence = min(float c | characteristic.hasImplications(endpoint.getAPotentialType(), false, c)) and
53+
confidence =
54+
min(float c |
55+
characteristic.hasImplications(CharacteristicsImpl::getAPotentialType(endpoint), false, c)
56+
) and
5457
confidence >= SharedCharacteristics::highConfidence() and
5558
any(ApplicationModeMetadataExtractor meta)
5659
.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output,
5760
isVarargsArray, _, extensibleType) and
5861
// It's valid for a node to be both a potential source/sanitizer and a sink. We don't want to include such nodes
59-
// as negative examples in the prompt, because they're ambiguous and might confuse the model, so we explicitly them here.
62+
// as negative examples in the prompt, because they're ambiguous and might confuse the model, so we explicitly exclude them here.
6063
not exists(EndpointCharacteristic characteristic2, float confidence2 |
64+
characteristic2 != characteristic
65+
|
6166
characteristic2.appliesToEndpoint(endpoint) and
6267
confidence2 >= SharedCharacteristics::maximalConfidence() and
63-
characteristic2.hasImplications(endpoint.getAPotentialType(), true, confidence2)
68+
characteristic2
69+
.hasImplications(CharacteristicsImpl::getAPotentialType(endpoint), true, confidence2)
6470
)
6571
}
6672

java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll

-12
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,6 @@ abstract class FrameworkModeEndpoint extends TFrameworkModeEndpoint {
8989

9090
abstract string getExtensibleType();
9191

92-
/**
93-
* Gets a potential type of this endpoint to make sure that sources are
94-
* associated with source types and sinks with sink types.
95-
*/
96-
AutomodelEndpointTypes::EndpointType getAPotentialType() {
97-
this.getExtensibleType() = "sourceModel" and
98-
result instanceof AutomodelEndpointTypes::SourceType
99-
or
100-
this.getExtensibleType() = "sinkModel" and
101-
result instanceof AutomodelEndpointTypes::SinkType
102-
}
103-
10492
string toString() { result = this.asTop().toString() }
10593

10694
Location getLocation() { result = this.asTop().getLocation() }

java/ql/automodel/src/AutomodelFrameworkModeExtractNegativeExamples.ql

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@ from
2121
where
2222
characteristic.appliesToEndpoint(endpoint) and
2323
// the node is known not to be an endpoint of any appropriate type
24-
forall(EndpointType tp | tp = endpoint.getAPotentialType() |
24+
forall(EndpointType tp | tp = CharacteristicsImpl::getAPotentialType(endpoint) |
2525
characteristic.hasImplications(tp, false, _)
2626
) and
2727
// the lowest confidence across all endpoint types should be at least highConfidence
28-
confidence = min(float c | characteristic.hasImplications(endpoint.getAPotentialType(), false, c)) and
28+
confidence =
29+
min(float c |
30+
characteristic.hasImplications(CharacteristicsImpl::getAPotentialType(endpoint), false, c)
31+
) and
2932
confidence >= SharedCharacteristics::highConfidence() and
3033
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output, parameterName,
3134
_, extensibleType) and
3235
// It's valid for a node to be both a potential source/sanitizer and a sink. We don't want to include such nodes
33-
// as negative examples in the prompt, because they're ambiguous and might confuse the model, so we explicitly them here.
36+
// as negative examples in the prompt, because they're ambiguous and might confuse the model, so we explicitly exclude them here.
3437
not exists(EndpointCharacteristic characteristic2, float confidence2 |
38+
characteristic2 != characteristic
39+
|
3540
characteristic2.appliesToEndpoint(endpoint) and
3641
confidence2 >= SharedCharacteristics::maximalConfidence() and
37-
characteristic2.hasImplications(endpoint.getAPotentialType(), true, confidence2)
42+
characteristic2
43+
.hasImplications(CharacteristicsImpl::getAPotentialType(endpoint), true, confidence2)
3844
) and
3945
message = characteristic
4046
select endpoint,

java/ql/automodel/src/AutomodelSharedCharacteristics.qll

+18-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ signature module CandidateSig {
1717
* DataFlow node class, or a subtype thereof.
1818
*/
1919
class Endpoint {
20-
EndpointType getAPotentialType();
20+
/**
21+
* Gets the kind of this endpoint, either "sourceModel" or "sinkModel".
22+
*/
23+
string getExtensibleType();
2124
}
2225

2326
/**
@@ -122,14 +125,26 @@ module SharedCharacteristics<CandidateSig Candidate> {
122125
characteristic.hasImplications(endpointType, true, maximalConfidence())
123126
}
124127

128+
/**
129+
* Gets a potential type of this endpoint to make sure that sources are
130+
* associated with source types and sinks with sink types.
131+
*/
132+
Candidate::EndpointType getAPotentialType(Candidate::Endpoint endpoint) {
133+
endpoint.getExtensibleType() = "sourceModel" and
134+
result instanceof Candidate::SourceType
135+
or
136+
endpoint.getExtensibleType() = "sinkModel" and
137+
result instanceof Candidate::SinkType
138+
}
139+
125140
/**
126141
* Holds if the given `endpoint` should be considered as a candidate for type `endpointType`,
127142
* and classified by the ML model.
128143
*
129144
* A candidate is an endpoint that cannot be excluded from `endpointType` based on its characteristics.
130145
*/
131146
predicate isCandidate(Candidate::Endpoint endpoint, Candidate::EndpointType endpointType) {
132-
endpointType = endpoint.getAPotentialType() and
147+
endpointType = getAPotentialType(endpoint) and
133148
not exists(getAnExcludingCharacteristic(endpoint, endpointType))
134149
}
135150

@@ -375,7 +390,7 @@ module SharedCharacteristics<CandidateSig Candidate> {
375390
* A negative characteristic that indicates that an endpoint was manually modeled as a neutral model.
376391
*/
377392
private class NeutralModelCharacteristic extends NeitherSourceNorSinkCharacteristic {
378-
NeutralModelCharacteristic() { this = "known non-endpoint" }
393+
NeutralModelCharacteristic() { this = "known non-sink" }
379394

380395
override predicate appliesToEndpoint(Candidate::Endpoint e) { Candidate::isNeutral(e) }
381396
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
| Test.java:48:10:50:3 | compareTo(...) | known sanitizer\nrelated locations: $@, $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:48:10:50:3 | compareTo(...) | CallContext | Test.java:48:10:50:3 | compareTo(...) | MethodDoc | Test.java:48:10:50:3 | compareTo(...) | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://false:1:1:1:1 | false | isVarargsArray | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
2-
| Test.java:49:4:49:5 | f2 | known non-endpoint\nrelated locations: $@, $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:48:10:50:3 | compareTo(...) | CallContext | Test.java:49:4:49:5 | f2 | MethodDoc | Test.java:49:4:49:5 | f2 | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
2+
| Test.java:49:4:49:5 | f2 | known non-sink\nrelated locations: $@, $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:48:10:50:3 | compareTo(...) | CallContext | Test.java:49:4:49:5 | f2 | MethodDoc | Test.java:49:4:49:5 | f2 | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
33
| Test.java:55:4:55:4 | p | taint step\nrelated locations: $@, $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:54:3:59:3 | walk(...) | CallContext | Test.java:55:4:55:4 | p | MethodDoc | Test.java:55:4:55:4 | p | ClassDoc | 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[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| com/github/codeql/test/PublicClass.java:26:18:26:26 | isIgnored | unexploitable (is-style boolean method)\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | com/github/codeql/test/PublicClass.java:26:18:26:26 | isIgnored | MethodDoc | com/github/codeql/test/PublicClass.java:26:18:26:26 | isIgnored | ClassDoc | file://com.github.codeql.test:1:1:1:1 | com.github.codeql.test | package | file://PublicClass:1:1:1:1 | PublicClass | type | file://true:1:1:1:1 | true | subtypes | file://isIgnored:1:1:1:1 | isIgnored | name | file://(Object):1:1:1:1 | (Object) | signature | file://:1:1:1:1 | | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://:1:1:1:1 | | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
22
| com/github/codeql/test/PublicClass.java:26:18:26:26 | isIgnored | unexploitable (is-style boolean method)\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | com/github/codeql/test/PublicClass.java:26:18:26:26 | isIgnored | MethodDoc | com/github/codeql/test/PublicClass.java:26:18:26:26 | isIgnored | ClassDoc | file://com.github.codeql.test:1:1:1:1 | com.github.codeql.test | package | file://PublicClass:1:1:1:1 | PublicClass | type | file://true:1:1:1:1 | true | subtypes | file://isIgnored:1:1:1:1 | isIgnored | name | file://(Object):1:1:1:1 | (Object) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://this:1:1:1:1 | this | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
33
| com/github/codeql/test/PublicClass.java:26:28:26:39 | input | unexploitable (is-style boolean method)\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | com/github/codeql/test/PublicClass.java:26:28:26:39 | input | MethodDoc | com/github/codeql/test/PublicClass.java:26:28:26:39 | input | ClassDoc | file://com.github.codeql.test:1:1:1:1 | com.github.codeql.test | package | file://PublicClass:1:1:1:1 | PublicClass | type | file://true:1:1:1:1 | true | subtypes | file://isIgnored:1:1:1:1 | isIgnored | name | file://(Object):1:1:1:1 | (Object) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://input:1:1:1:1 | input | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
4-
| java/io/File.java:4:16:4:24 | compareTo | known non-endpoint\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[this]:1:1:1:1 | Parameter[this] | output | file://this:1:1:1:1 | this | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
5-
| java/io/File.java:4:16:4:24 | compareTo | known non-endpoint\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://this:1:1:1:1 | this | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
6-
| java/io/File.java:5:9:5:21 | pathname | known non-endpoint\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[0]:1:1:1:1 | Parameter[0] | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
7-
| java/io/File.java:5:9:5:21 | pathname | known non-endpoint\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
4+
| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[this]:1:1:1:1 | Parameter[this] | output | file://this:1:1:1:1 | this | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
5+
| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://this:1:1:1:1 | this | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |
6+
| java/io/File.java:5:9:5:21 | pathname | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[0]:1:1:1:1 | Parameter[0] | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType |
7+
| java/io/File.java:5:9:5:21 | pathname | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType |

0 commit comments

Comments
 (0)