|
| 1 | +/** |
| 2 | + * For internal use only. |
| 3 | + */ |
| 4 | + |
| 5 | +import experimental.adaptivethreatmodeling.EndpointTypes |
| 6 | +private import semmle.javascript.security.dataflow.SqlInjectionCustomizations |
| 7 | +private import semmle.javascript.security.dataflow.DomBasedXssCustomizations |
| 8 | +private import semmle.javascript.security.dataflow.NosqlInjectionCustomizations |
| 9 | +private import semmle.javascript.security.dataflow.TaintedPathCustomizations |
| 10 | + |
| 11 | +/** |
| 12 | + * A set of characteristics that a particular endpoint might have. This set of characteristics is used to make decisions |
| 13 | + * about whether to include the endpoint in the training set and with what label, as well as whether to score the |
| 14 | + * endpoint at inference time. |
| 15 | + */ |
| 16 | +abstract class EndpointCharacteristic extends string { |
| 17 | + /** |
| 18 | + * Holds when the string matches the name of the characteristic, which should describe some characteristic of the |
| 19 | + * endpoint that is meaningful for determining whether it's a sink and if so of which type |
| 20 | + */ |
| 21 | + bindingset[this] |
| 22 | + EndpointCharacteristic() { any() } |
| 23 | + |
| 24 | + /** |
| 25 | + * Holds for endpoints that have this characteristic. This predicate contains the logic that applies characteristics |
| 26 | + * to the appropriate set of dataflow nodes. |
| 27 | + */ |
| 28 | + abstract predicate getEndpoints(DataFlow::Node n); |
| 29 | + |
| 30 | + /** |
| 31 | + * This predicate describes what the characteristic tells us about an endpoint. |
| 32 | + * |
| 33 | + * Params: |
| 34 | + * endpointClass: Class 0 is the negative class. Each positive int corresponds to a single sink type. |
| 35 | + * isPositiveIndicator: Does this characteristic indicate this endpoint _is_ a member of the class, or that it |
| 36 | + * _isn't_ a member of the class? |
| 37 | + * confidence: A number in [0, 1], which tells us how strong an indicator this characteristic is for the endpoint |
| 38 | + * belonging / not belonging to the given class. |
| 39 | + */ |
| 40 | + abstract predicate getImplications( |
| 41 | + EndpointType endpointClass, boolean isPositiveIndicator, float confidence |
| 42 | + ); |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * Endpoints identified as "DomBasedXssSink" by the standard JavaScript libraries are XSS sinks with maximal confidence. |
| 47 | + */ |
| 48 | +private class DomBasedXssSinkCharacteristic extends EndpointCharacteristic { |
| 49 | + DomBasedXssSinkCharacteristic() { this = "DomBasedXssSink" } |
| 50 | + |
| 51 | + override predicate getEndpoints(DataFlow::Node n) { n instanceof DomBasedXss::Sink } |
| 52 | + |
| 53 | + override predicate getImplications( |
| 54 | + EndpointType endpointClass, boolean isPositiveIndicator, float confidence |
| 55 | + ) { |
| 56 | + endpointClass instanceof XssSinkType and isPositiveIndicator = true and confidence = 1.0 |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * Endpoints identified as "TaintedPathSink" by the standard JavaScript libraries are path injection sinks with maximal |
| 62 | + * confidence. |
| 63 | + */ |
| 64 | +private class TaintedPathSinkCharacteristic extends EndpointCharacteristic { |
| 65 | + TaintedPathSinkCharacteristic() { this = "TaintedPathSink" } |
| 66 | + |
| 67 | + override predicate getEndpoints(DataFlow::Node n) { n instanceof TaintedPath::Sink } |
| 68 | + |
| 69 | + override predicate getImplications( |
| 70 | + EndpointType endpointClass, boolean isPositiveIndicator, float confidence |
| 71 | + ) { |
| 72 | + endpointClass instanceof TaintedPathSinkType and isPositiveIndicator = true and confidence = 1.0 |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * Endpoints identified as "SqlInjectionSink" by the standard JavaScript libraries are SQL injection sinks with maximal |
| 78 | + * confidence. |
| 79 | + */ |
| 80 | +private class SqlInjectionSinkCharacteristic extends EndpointCharacteristic { |
| 81 | + SqlInjectionSinkCharacteristic() { this = "SqlInjectionSink" } |
| 82 | + |
| 83 | + override predicate getEndpoints(DataFlow::Node n) { n instanceof SqlInjection::Sink } |
| 84 | + |
| 85 | + override predicate getImplications( |
| 86 | + EndpointType endpointClass, boolean isPositiveIndicator, float confidence |
| 87 | + ) { |
| 88 | + endpointClass instanceof SqlInjectionSinkType and |
| 89 | + isPositiveIndicator = true and |
| 90 | + confidence = 1.0 |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +/** |
| 95 | + * Endpoints identified as "NosqlInjectionSink" by the standard JavaScript libraries are NoSQL injection sinks with |
| 96 | + * maximal confidence. |
| 97 | + */ |
| 98 | +private class NosqlInjectionSinkCharacteristic extends EndpointCharacteristic { |
| 99 | + NosqlInjectionSinkCharacteristic() { this = "NosqlInjectionSink" } |
| 100 | + |
| 101 | + override predicate getEndpoints(DataFlow::Node n) { n instanceof NosqlInjection::Sink } |
| 102 | + |
| 103 | + override predicate getImplications( |
| 104 | + EndpointType endpointClass, boolean isPositiveIndicator, float confidence |
| 105 | + ) { |
| 106 | + endpointClass instanceof NosqlInjectionSinkType and |
| 107 | + isPositiveIndicator = true and |
| 108 | + confidence = 1.0 |
| 109 | + } |
| 110 | +} |
0 commit comments