make framework mode explicit in file/module names

This commit is contained in:
Stephan Brandauer
2023-05-03 14:36:42 +02:00
parent dfb9d88198
commit 6d29273c43
2 changed files with 15 additions and 22 deletions

View File

@@ -17,7 +17,7 @@ private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclus
import AutomodelSharedCharacteristics as SharedCharacteristics
import AutomodelEndpointTypes as AutomodelEndpointTypes
module CandidatesImpl implements SharedCharacteristics::CandidateSig {
module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
class Endpoint = DataFlow::ParameterNode;
class EndpointType = AutomodelEndpointTypes::EndpointType;
@@ -29,7 +29,7 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
// Sanitizers are currently not modeled in MaD. TODO: check if this has large negative impact.
predicate isSanitizer(Endpoint e, EndpointType t) { none() }
RelatedLocation toRelatedLocation(Endpoint e) { result = e.asParameter() }
RelatedLocation asLocation(Endpoint e) { result = e.asParameter() }
predicate isKnownLabel(string label, string humanReadableLabel, EndpointType type) {
label = "read-file" and
@@ -89,18 +89,11 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
predicate hasMetadata(Endpoint e, string metadata) {
exists(
string package, string type, boolean subtypes, string name, string signature, string ext,
int input, boolean isPublic, boolean isFinal, boolean isStatic
string package, string type, boolean subtypes, string name, string signature, int input,
boolean isPublic, boolean isFinal, boolean isStatic
|
hasMetadata(e, package, type, name, signature, input, isFinal, isStatic, isPublic) and
(if isFinal = true or isStatic = true then subtypes = false else subtypes = true) and
ext = "" and
/*
* "ext" will always be empty for automodeling; it's a mechanism for
* specifying that the model should apply for parameters that have
* a certain annotation.
*/
metadata =
"{" //
+ "'Package': '" + package //
@@ -125,11 +118,11 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
Callable getCallable(Endpoint e) { result = e.getEnclosingCallable() }
module CharacteristicsImpl = SharedCharacteristics::SharedCharacteristics<CandidatesImpl>;
module CharacteristicsImpl = SharedCharacteristics::SharedCharacteristics<FrameworkCandidatesImpl>;
class EndpointCharacteristic = CharacteristicsImpl::EndpointCharacteristic;
class Endpoint = CandidatesImpl::Endpoint;
class Endpoint = FrameworkCandidatesImpl::Endpoint;
/*
* Predicates that are used to surface prompt examples and candidates for classification with an ML model.
@@ -181,7 +174,7 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
UnexploitableIsCharacteristic() { this = "unexploitable (is-style boolean method)" }
override predicate appliesToEndpoint(Endpoint e) {
not CandidatesImpl::isSink(e, _) and
not FrameworkCandidatesImpl::isSink(e, _) and
getCallable(e).getName().matches("is%") and
getCallable(e).getReturnType() instanceof BooleanType
}
@@ -199,7 +192,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
UnexploitableExistsCharacteristic() { this = "unexploitable (existence-checking boolean method)" }
override predicate appliesToEndpoint(Endpoint e) {
not CandidatesImpl::isSink(e, _) and
not FrameworkCandidatesImpl::isSink(e, _) and
exists(Callable callable |
callable = getCallable(e) and
(

View File

@@ -13,7 +13,7 @@ float mediumConfidence() { result = 0.6 }
*/
signature module CandidateSig {
/**
* An endpoint is a potential candidate for modelling. This will typically be bound to the language's
* An endpoint is a potential candidate for modeling. This will typically be bound to the language's
* DataFlow node class, or a subtype thereof.
*/
class Endpoint;
@@ -26,17 +26,17 @@ signature module CandidateSig {
/**
* A class label for an endpoint.
*/
class EndpointType;
class EndpointType extends string;
/**
* An EndpointType that denotes the absence of any sink.
*/
class NegativeEndpointType extends EndpointType;
RelatedLocation toRelatedLocation(Endpoint e);
RelatedLocation asLocation(Endpoint e);
/**
* Defines what labels are known, and what endpoint type they correspond to.
* Defines what MaD labels are known, and what endpoint type they correspond to.
*/
predicate isKnownLabel(string label, string humanReadableLabel, EndpointType type);
@@ -117,7 +117,7 @@ module SharedCharacteristics<CandidateSig Candidate> {
Candidate::RelatedLocation getRelatedLocationOrCandidate(Candidate::Endpoint e, string name) {
if exists(Candidate::getRelatedLocation(e, name))
then result = Candidate::getRelatedLocation(e, name)
else result = Candidate::toRelatedLocation(e)
else result = Candidate::asLocation(e)
}
/**
@@ -152,8 +152,8 @@ module SharedCharacteristics<CandidateSig Candidate> {
*/
abstract class EndpointCharacteristic extends string {
/**
* Holds when the string matches the name of the characteristic, which should describe some characteristic of the
* endpoint that is meaningful for determining whether it's a sink and if so of which type
* The name of the characteristic. This should describe some property of an
* endpoint that is meaningful for determining whether it's a sink, and if so, of which sink type.
*/
bindingset[this]
EndpointCharacteristic() { any() }