Skip to content

Commit 7c02a9b

Browse files
author
Stephan Brandauer
authored
Merge pull request github#13185 from github/fix-automodel-extraction-parameterName
Java: Automodel Extraction Parameter Name Fix
2 parents b46983a + a5ef738 commit 7c02a9b

4 files changed

+19
-15
lines changed

java/ql/src/Telemetry/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class MetadataExtractor extends string {
2727

2828
abstract predicate hasMetadata(
2929
DataFlow::ParameterNode e, string package, string type, boolean subtypes, string name,
30-
string signature, int input
30+
string signature, int input, string parameterName
3131
);
3232
}
3333

@@ -167,14 +167,15 @@ class FrameworkModeMetadataExtractor extends MetadataExtractor {
167167

168168
override predicate hasMetadata(
169169
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
170-
int input
170+
int input, string parameterName
171171
) {
172172
exists(Callable callable |
173173
e.asParameter() = callable.getParameter(input) and
174174
package = callable.getDeclaringType().getPackage().getName() and
175175
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
176176
subtypes = this.considerSubtypes(callable) and
177-
name = e.toString() and
177+
name = callable.getName() and
178+
parameterName = e.asParameter().getName() and
178179
signature = ExternalFlow::paramsString(callable)
179180
)
180181
}

java/ql/src/Telemetry/AutomodelFrameworkModeExtractCandidates.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private import AutomodelSharedUtil
1717

1818
from
1919
Endpoint endpoint, string message, MetadataExtractor meta, string package, string type,
20-
boolean subtypes, string name, string signature, int input
20+
boolean subtypes, string name, string signature, int input, string parameterName
2121
where
2222
not exists(CharacteristicsImpl::UninterestingToModelCharacteristic u |
2323
u.appliesToEndpoint(endpoint)
@@ -28,7 +28,7 @@ where
2828
// overlap between our detected sinks and the pre-existing modeling. We assume that, if a sink has already been
2929
// modeled in a MaD model, then it doesn't belong to any additional sink types, and we don't need to reexamine it.
3030
not CharacteristicsImpl::isSink(endpoint, _) and
31-
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input) and
31+
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, parameterName) and
3232
// The message is the concatenation of all sink types for which this endpoint is known neither to be a sink nor to be
3333
// a non-sink, and we surface only endpoints that have at least one such sink type.
3434
message =
@@ -39,12 +39,13 @@ where
3939
sinkType, ", "
4040
)
4141
select endpoint,
42-
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
42+
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@.", //
4343
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
4444
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
4545
package.(DollarAtString), "package", //
4646
type.(DollarAtString), "type", //
4747
subtypes.toString().(DollarAtString), "subtypes", //
4848
name.(DollarAtString), "name", //
4949
signature.(DollarAtString), "signature", //
50-
input.toString().(DollarAtString), "input" //
50+
input.toString().(DollarAtString), "input", //
51+
parameterName.(DollarAtString), "parameterName" //

java/ql/src/Telemetry/AutomodelFrameworkModeExtractNegativeExamples.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ private import AutomodelSharedUtil
1515
from
1616
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
1717
MetadataExtractor meta, string package, string type, boolean subtypes, string name,
18-
string signature, int input
18+
string signature, int input, string parameterName
1919
where
2020
characteristic.appliesToEndpoint(endpoint) and
2121
confidence >= SharedCharacteristics::highConfidence() and
2222
characteristic.hasImplications(any(NegativeSinkType negative), true, confidence) and
2323
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
2424
// certain about in the prompt.
2525
not erroneousEndpoints(endpoint, _, _, _, _, false) and
26-
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input) and
26+
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, parameterName) and
2727
// It's valid for a node to satisfy the logic for both `isSink` and `isSanitizer`, but in that case it will be
2828
// treated by the actual query as a sanitizer, since the final logic is something like
2929
// `isSink(n) and not isSanitizer(n)`. We don't want to include such nodes as negative examples in the prompt, because
@@ -36,12 +36,13 @@ where
3636
) and
3737
message = characteristic
3838
select endpoint,
39-
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
39+
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@.", //
4040
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
4141
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
4242
package.(DollarAtString), "package", //
4343
type.(DollarAtString), "type", //
4444
subtypes.toString().(DollarAtString), "subtypes", //
4545
name.(DollarAtString), "name", //
4646
signature.(DollarAtString), "signature", //
47-
input.toString().(DollarAtString), "input" //
47+
input.toString().(DollarAtString), "input", //
48+
parameterName.(DollarAtString), "parameterName" //

java/ql/src/Telemetry/AutomodelFrameworkModeExtractPositiveExamples.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ private import AutomodelSharedUtil
1414

1515
from
1616
Endpoint endpoint, SinkType sinkType, MetadataExtractor meta, string package, string type,
17-
boolean subtypes, string name, string signature, int input
17+
boolean subtypes, string name, string signature, int input, string parameterName
1818
where
1919
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
2020
// certain about in the prompt.
2121
not erroneousEndpoints(endpoint, _, _, _, _, false) and
22-
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input) and
22+
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, parameterName) and
2323
// Extract positive examples of sinks belonging to the existing ATM query configurations.
2424
CharacteristicsImpl::isKnownSink(endpoint, sinkType)
2525
select endpoint,
26-
sinkType + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
26+
sinkType + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@.", //
2727
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
2828
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
2929
package.(DollarAtString), "package", //
3030
type.(DollarAtString), "type", //
3131
subtypes.toString().(DollarAtString), "subtypes", //
3232
name.(DollarAtString), "name", //
3333
signature.(DollarAtString), "signature", //
34-
input.toString().(DollarAtString), "input" //
34+
input.toString().(DollarAtString), "input", //
35+
parameterName.(DollarAtString), "parameterName" //

0 commit comments

Comments
 (0)