Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e21f14

Browse files
author
Stephan Brandauer
committed
Java: update extraction query metadata
1 parent 7c3bc26 commit 6e21f14

6 files changed

Lines changed: 89 additions & 12 deletions

java/ql/src/Telemetry/AutomodelApplicationModeExtractCandidates.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*
55
* Note: This query does not actually classify the endpoints using the model.
66
*
7-
* @name Automodel candidates
8-
* @description A query to extract automodel candidates.
7+
* @name Automodel candidates (application mode)
8+
* @description A query to extract automodel candidates in application mode.
99
* @kind problem
1010
* @severity info
1111
* @id java/ml/extract-automodel-application-candidates
12-
* @tags internal automodel extract candidates application-mode
12+
* @tags internal extract automodel application-mode candidates
1313
*/
1414

1515
private import AutomodelApplicationModeCharacteristics
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Surfaces endpoints that are non-sinks with high confidence, for use as negative examples in the prompt.
3+
*
4+
* @name Negative examples (application mode)
5+
* @kind problem
6+
* @severity info
7+
* @id java/ml/extract-automodel-application-negative-examples
8+
* @tags internal extract automodel application-mode negative examples
9+
*/
10+
11+
private import AutomodelApplicationModeCharacteristics
12+
private import AutomodelEndpointTypes
13+
private import AutomodelSharedUtil
14+
15+
from
16+
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
17+
MetadataExtractor meta, string package, string type, boolean subtypes, string name,
18+
string signature, string input
19+
where
20+
characteristic.appliesToEndpoint(endpoint) and
21+
confidence >= SharedCharacteristics::highConfidence() and
22+
characteristic.hasImplications(any(NegativeSinkType negative), true, confidence) and
23+
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
24+
// certain about in the prompt.
25+
not erroneousEndpoints(endpoint, _, _, _, _, false) and
26+
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input) and
27+
// It's valid for a node to satisfy the logic for both `isSink` and `isSanitizer`, but in that case it will be
28+
// treated by the actual query as a sanitizer, since the final logic is something like
29+
// `isSink(n) and not isSanitizer(n)`. We don't want to include such nodes as negative examples in the prompt, because
30+
// they're ambiguous and might confuse the model, so we explicitly exclude all known sinks from the negative examples.
31+
not exists(EndpointCharacteristic characteristic2, float confidence2, SinkType positiveType |
32+
not positiveType instanceof NegativeSinkType and
33+
characteristic2.appliesToEndpoint(endpoint) and
34+
confidence2 >= SharedCharacteristics::maximalConfidence() and
35+
characteristic2.hasImplications(positiveType, true, confidence2)
36+
) and
37+
message = characteristic
38+
select endpoint, message + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
39+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
40+
package.(DollarAtString), "package", //
41+
type.(DollarAtString), "type", //
42+
subtypes.toString().(DollarAtString), "subtypes", //
43+
name.(DollarAtString), "name", //
44+
signature.(DollarAtString), "signature", //
45+
input.(DollarAtString), "input" //
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Surfaces endpoints that are sinks with high confidence, for use as positive examples in the prompt.
3+
*
4+
* @name Positive examples (application mode)
5+
* @kind problem
6+
* @severity info
7+
* @id java/ml/extract-automodel-application-positive-examples
8+
* @tags internal extract automodel application-mode positive examples
9+
*/
10+
11+
private import AutomodelApplicationModeCharacteristics
12+
private import AutomodelEndpointTypes
13+
private import AutomodelSharedUtil
14+
15+
from
16+
Endpoint endpoint, SinkType sinkType, MetadataExtractor meta, string package, string type,
17+
boolean subtypes, string name, string signature, string input
18+
where
19+
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
20+
// certain about in the prompt.
21+
not erroneousEndpoints(endpoint, _, _, _, _, false) and
22+
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input) and
23+
// Extract positive examples of sinks belonging to the existing ATM query configurations.
24+
CharacteristicsImpl::isKnownSink(endpoint, sinkType)
25+
select endpoint, sinkType + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
26+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
27+
package.(DollarAtString), "package", //
28+
type.(DollarAtString), "type", //
29+
subtypes.toString().(DollarAtString), "subtypes", //
30+
name.(DollarAtString), "name", //
31+
signature.(DollarAtString), "signature", //
32+
input.(DollarAtString), "input" //

java/ql/src/Telemetry/AutomodelFrameworkModeExtractCandidates.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*
55
* Note: This query does not actually classify the endpoints using the model.
66
*
7-
* @name Automodel candidates
8-
* @description A query to extract automodel candidates.
7+
* @name Automodel candidates (framework mode)
8+
* @description A query to extract automodel candidates in framework mode.
99
* @kind problem
1010
* @severity info
1111
* @id java/ml/extract-automodel-framework-candidates
12-
* @tags internal automodel extract candidates framework-mode
12+
* @tags internal extract automodel framework-mode candidates
1313
*/
1414

1515
private import AutomodelFrameworkModeCharacteristics

java/ql/src/Telemetry/AutomodelFrameworkModeExtractNegativeExamples.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* Surfaces endpoints that are non-sinks with high confidence, for use as negative examples in the prompt.
33
*
4-
* @name Negative examples (experimental)
4+
* @name Negative examples (framework mode)
55
* @kind problem
66
* @severity info
7-
* @id java/ml/non-sink
8-
* @tags internal automodel extract examples negative framework-mode
7+
* @id java/ml/extract-automodel-framework-negative-examples
8+
* @tags internal extract automodel framework-mode negative examples
99
*/
1010

1111
private import AutomodelFrameworkModeCharacteristics

java/ql/src/Telemetry/AutomodelFrameworkModeExtractPositiveExamples.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* Surfaces endpoints that are sinks with high confidence, for use as positive examples in the prompt.
33
*
4-
* @name Positive examples (experimental)
4+
* @name Positive examples (framework mode)
55
* @kind problem
66
* @severity info
7-
* @id java/ml/known-sink
8-
* @tags internal automodel extract examples positive framework-mode
7+
* @id java/ml/extract-automodel-framework-positive-examples
8+
* @tags internal extract automodel framework-mode positive examples
99
*/
1010

1111
private import AutomodelFrameworkModeCharacteristics

0 commit comments

Comments
 (0)