Skip to content

Commit d7beda7

Browse files
author
Stephan Brandauer
authored
Merge pull request github#14197 from github/kaeluka/framework-mode-source-candidates
Java: Framework mode source candidates
2 parents 30d7f0c + fdbc553 commit d7beda7

18 files changed

+215
-282
lines changed

java/ql/automodel/src/AutomodelAlertSinkUtil.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class PotentialSinkModelExpr extends Expr {
9696
or
9797
this = call.getQualifier() and argIdx = -1
9898
) and
99-
input = getArgumentForIndex(argIdx) and
99+
(if argIdx = -1 then input = "Argument[this]" else input = "Argument[" + argIdx + "]") and
100100
package = callable.getDeclaringType().getPackage().getName() and
101101
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
102102
subtypes = considerSubtypes(callable) and

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -569,72 +569,3 @@ private class CannotBeTaintedCharacteristic extends CharacteristicsImpl::LikelyN
569569
FlowSummaryImpl::Private::Steps::summarySetterStep(_, _, e.asNode(), _)
570570
}
571571
}
572-
573-
/**
574-
* Holds if the given endpoint has a self-contradictory combination of characteristics. Detects errors in our endpoint
575-
* characteristics. Lists the problematic characteristics and their implications for all such endpoints, together with
576-
* an error message indicating why this combination is problematic.
577-
*
578-
* Copied from
579-
* javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/ContradictoryEndpointCharacteristics.ql
580-
*/
581-
predicate erroneousEndpoints(
582-
Endpoint endpoint, EndpointCharacteristic characteristic,
583-
AutomodelEndpointTypes::EndpointType endpointType, float confidence, string errorMessage,
584-
boolean ignoreKnownModelingErrors
585-
) {
586-
// An endpoint's characteristics should not include positive indicators with medium/high confidence for more than one
587-
// sink/source type (including the negative type).
588-
exists(
589-
EndpointCharacteristic characteristic2, AutomodelEndpointTypes::EndpointType endpointClass2,
590-
float confidence2
591-
|
592-
endpointType != endpointClass2 and
593-
(
594-
endpointType instanceof AutomodelEndpointTypes::SinkType and
595-
endpointClass2 instanceof AutomodelEndpointTypes::SinkType
596-
or
597-
endpointType instanceof AutomodelEndpointTypes::SourceType and
598-
endpointClass2 instanceof AutomodelEndpointTypes::SourceType
599-
) and
600-
characteristic.appliesToEndpoint(endpoint) and
601-
characteristic2.appliesToEndpoint(endpoint) and
602-
characteristic.hasImplications(endpointType, true, confidence) and
603-
characteristic2.hasImplications(endpointClass2, true, confidence2) and
604-
confidence > SharedCharacteristics::mediumConfidence() and
605-
confidence2 > SharedCharacteristics::mediumConfidence() and
606-
(
607-
ignoreKnownModelingErrors = true and
608-
not knownOverlappingCharacteristics(characteristic, characteristic2)
609-
or
610-
ignoreKnownModelingErrors = false
611-
)
612-
) and
613-
errorMessage = "Endpoint has high-confidence positive indicators for multiple classes"
614-
or
615-
// An endpoint's characteristics should not include positive indicators with medium/high confidence for some class and
616-
// also include negative indicators with medium/high confidence for this same class.
617-
exists(EndpointCharacteristic characteristic2, float confidence2 |
618-
characteristic.appliesToEndpoint(endpoint) and
619-
characteristic2.appliesToEndpoint(endpoint) and
620-
characteristic.hasImplications(endpointType, true, confidence) and
621-
characteristic2.hasImplications(endpointType, false, confidence2) and
622-
confidence > SharedCharacteristics::mediumConfidence() and
623-
confidence2 > SharedCharacteristics::mediumConfidence()
624-
) and
625-
ignoreKnownModelingErrors = false and
626-
errorMessage = "Endpoint has high-confidence positive and negative indicators for the same class"
627-
}
628-
629-
/**
630-
* Holds if `characteristic1` and `characteristic2` are among the pairs of currently known positive characteristics that
631-
* have some overlap in their results. This indicates a problem with the underlying Java modeling. Specifically,
632-
* `PathCreation` is prone to FPs.
633-
*/
634-
private predicate knownOverlappingCharacteristics(
635-
EndpointCharacteristic characteristic1, EndpointCharacteristic characteristic2
636-
) {
637-
characteristic1 != characteristic2 and
638-
characteristic1 = ["mad taint step", "create path", "read file", "known non-sink"] and
639-
characteristic2 = ["mad taint step", "create path", "read file", "known non-sink"]
640-
}

java/ql/automodel/src/AutomodelApplicationModeExtractCandidates.ql

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ private Endpoint getSampleForSignature(
5555
}
5656

5757
from
58-
Endpoint endpoint, string message, ApplicationModeMetadataExtractor meta, DollarAtString package,
58+
Endpoint endpoint, ApplicationModeMetadataExtractor meta, DollarAtString package,
5959
DollarAtString type, DollarAtString subtypes, DollarAtString name, DollarAtString signature,
6060
DollarAtString input, DollarAtString output, DollarAtString isVarargsArray,
6161
DollarAtString alreadyAiModeled, DollarAtString extensibleType
6262
where
6363
not exists(CharacteristicsImpl::UninterestingToModelCharacteristic u |
6464
u.appliesToEndpoint(endpoint)
6565
) and
66+
CharacteristicsImpl::isSinkCandidate(endpoint, _) and
6667
endpoint =
6768
getSampleForSignature(9, package, type, subtypes, name, signature, input, output,
6869
isVarargsArray, extensibleType) and
@@ -78,19 +79,9 @@ where
7879
CharacteristicsImpl::isModeled(endpoint, _, _, alreadyAiModeled)
7980
) and
8081
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output, isVarargsArray) and
81-
includeAutomodelCandidate(package, type, name, signature) and
82-
// The message is the concatenation of all sink types for which this endpoint is known neither to be a sink nor to be
83-
// a non-sink, and we surface only endpoints that have at least one such sink type.
84-
message =
85-
strictconcat(AutomodelEndpointTypes::SinkType sinkType |
86-
not CharacteristicsImpl::isKnownAs(endpoint, sinkType, _) and
87-
CharacteristicsImpl::isSinkCandidate(endpoint, sinkType)
88-
|
89-
sinkType, ", "
90-
)
82+
includeAutomodelCandidate(package, type, name, signature)
9183
select endpoint.asNode(),
92-
message + "\nrelated locations: $@, $@, $@." +
93-
"\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@, $@.", //
84+
"Related locations: $@, $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@, $@.", //
9485
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
9586
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
9687
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //

java/ql/automodel/src/AutomodelApplicationModeExtractNegativeExamples.ql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ where
5050
extensibleType = endpoint.getExtensibleType() and
5151
confidence >= SharedCharacteristics::highConfidence() and
5252
characteristic.hasImplications(any(NegativeSinkType negative), true, confidence) and
53-
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
54-
// certain about in the prompt.
55-
not erroneousEndpoints(endpoint, _, _, _, _, false) and
5653
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output, isVarargsArray) and
5754
// It's valid for a node to satisfy the logic for both `isSink` and `isSanitizer`, but in that case it will be
5855
// treated by the actual query as a sanitizer, since the final logic is something like

java/ql/automodel/src/AutomodelApplicationModeExtractPositiveExamples.ql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ from
1818
DollarAtString signature, DollarAtString input, DollarAtString output,
1919
DollarAtString isVarargsArray, DollarAtString extensibleType
2020
where
21-
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
22-
// certain about in the prompt.
23-
not erroneousEndpoints(endpoint, _, _, _, _, false) and
2421
extensibleType = endpoint.getExtensibleType() and
2522
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output, isVarargsArray) and
2623
// Extract positive examples of sinks belonging to the existing ATM query configurations.

0 commit comments

Comments
 (0)