diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll index b634aa7d1a5..739546dde46 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll @@ -49,6 +49,8 @@ module EntityFramework { StoredFlowSource() { this.asExpr() = any(PropertyRead read | read.getTarget() instanceof MappedProperty) } + + override string getSourceType() { result = "ORM mapped property" } } private class EFClass extends Class { diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/NHibernate.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/NHibernate.qll index a13c84250c5..74796ccedd1 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/NHibernate.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/NHibernate.qll @@ -91,6 +91,8 @@ module NHibernate { StoredFlowSource() { this.asExpr() = any(PropertyRead read | read.getTarget() instanceof MappedProperty) } + + override string getSourceType() { result = "ORM mapped property" } } /** diff --git a/csharp/ql/lib/semmle/code/csharp/security/auth/InsecureDirectObjectReferenceQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/auth/InsecureDirectObjectReferenceQuery.qll index d4fa6401650..858adcc2268 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/auth/InsecureDirectObjectReferenceQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/auth/InsecureDirectObjectReferenceQuery.qll @@ -1,7 +1,8 @@ /** Definitions for the Insecure Direct Object Reference query */ import csharp -import semmle.code.csharp.dataflow.flowsources.Remote +import semmle.code.csharp.security.dataflow.flowsources.FlowSources +deprecated import semmle.code.csharp.dataflow.flowsources.Remote import ActionMethods /** @@ -17,7 +18,7 @@ private predicate needsChecks(ActionMethod m) { m.isEdit() and not m.isAdmin() } * that may indicate that it's used as the ID for some resource */ private predicate hasIdParameter(ActionMethod m) { - exists(RemoteFlowSource src | src.getEnclosingCallable() = m | + exists(ThreatModelFlowSource src | src.getEnclosingCallable() = m | src.asParameter().getName().toLowerCase().matches(["%id", "%idx"]) or // handle cases like `Request.QueryString["Id"]` diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll index d41c6b8f811..fdfd422c47b 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll @@ -3,8 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote -private import semmle.code.csharp.security.dataflow.flowsources.Local +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.codedom.Compiler private import semmle.code.csharp.security.Sanitizers private import semmle.code.csharp.dataflow.internal.ExternalFlow @@ -55,11 +54,24 @@ private module CodeInjectionConfig implements DataFlow::ConfigSig { */ module CodeInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } -/** A source of local user input. */ -class LocalSource extends Source instanceof LocalFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of local user input. + */ +deprecated class LocalSource extends DataFlow::Node instanceof LocalFlowSource { } + +private class AddLocalSource extends Source instanceof LocalFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } private class SimpleTypeSanitizer extends Sanitizer, SimpleTypeSanitizedExpr { } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/CommandInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/CommandInjectionQuery.qll index b174405443f..d0b24125ba9 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/CommandInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/CommandInjectionQuery.qll @@ -3,7 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.Diagnostics private import semmle.code.csharp.security.Sanitizers private import semmle.code.csharp.dataflow.internal.ExternalFlow @@ -64,8 +64,15 @@ module CommandInjectionConfig implements DataFlow::ConfigSig { */ module CommandInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** Command Injection sinks defined through Models as Data. */ private class ExternalCommandInjectionExprSink extends Sink { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ConditionalBypassQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ConditionalBypassQuery.qll index e919684d751..a8938ecc6c9 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ConditionalBypassQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ConditionalBypassQuery.qll @@ -6,7 +6,7 @@ import csharp private import semmle.code.csharp.controlflow.Guards private import semmle.code.csharp.controlflow.BasicBlocks -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.System private import semmle.code.csharp.frameworks.system.Net private import semmle.code.csharp.security.SensitiveActions @@ -60,8 +60,15 @@ private module ConditionalBypassConfig implements DataFlow::ConfigSig { */ module ConditionalBypass = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** The result of a reverse dns may be user-controlled. */ class ReverseDnsSource extends Source { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExposureOfPrivateInformationQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExposureOfPrivateInformationQuery.qll index 0b53d9d1ca6..03db7fadf81 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExposureOfPrivateInformationQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExposureOfPrivateInformationQuery.qll @@ -3,7 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.security.dataflow.flowsinks.ExternalLocationSink private import semmle.code.csharp.security.PrivateData diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll index e1630503da5..3075fe53a87 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll @@ -5,7 +5,7 @@ import csharp private import semmle.code.csharp.commons.QualifiedName -private import semmle.code.csharp.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.System private import semmle.code.csharp.dataflow.FlowSummary @@ -92,19 +92,19 @@ class ExternalApiDataNode extends DataFlow::Node { deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration { UntrustedDataToExternalApiConfig() { this = "UntrustedDataToExternalAPIConfig" } - override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } + override predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource } override predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode } } -/** A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */ +/** A configuration for tracking flow from `ThreatModelFlowSource`s to `ExternalApiDataNode`s. */ private module RemoteSourceToExternalApiConfig implements DataFlow::ConfigSig { - predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } + predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource } predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode } } -/** A module for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */ +/** A module for tracking flow from `ThreatModelFlowSource`s to `ExternalApiDataNode`s. */ module RemoteSourceToExternalApi = TaintTracking::Global; /** A node representing untrusted data being passed to an external API. */ diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/LDAPInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/LDAPInjectionQuery.qll index 25134fbcb12..58a34f7604b 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/LDAPInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/LDAPInjectionQuery.qll @@ -4,7 +4,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.DirectoryServices private import semmle.code.csharp.frameworks.system.directoryservices.Protocols private import semmle.code.csharp.security.Sanitizers @@ -66,8 +66,15 @@ module LdapInjectionConfig implements DataFlow::ConfigSig { */ module LdapInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreadModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** LDAP sinks defined through Models as Data. */ private class ExternalLdapExprSink extends Sink { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/LogForgingQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/LogForgingQuery.qll index 800e86457b4..ed6e69f0709 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/LogForgingQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/LogForgingQuery.qll @@ -3,7 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.System private import semmle.code.csharp.frameworks.system.text.RegularExpressions private import semmle.code.csharp.security.Sanitizers @@ -57,7 +57,7 @@ private module LogForgingConfig implements DataFlow::ConfigSig { module LogForging = TaintTracking::Global; /** A source of remote user input. */ -private class RemoteSource extends Source instanceof RemoteFlowSource { } +private class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } private class HtmlSanitizer extends Sanitizer { HtmlSanitizer() { this.asExpr() instanceof HtmlSanitizedExpr } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/MissingXMLValidationQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/MissingXMLValidationQuery.qll index 676b77b8446..914239bf7d5 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/MissingXMLValidationQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/MissingXMLValidationQuery.qll @@ -4,7 +4,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.Xml private import semmle.code.csharp.security.Sanitizers @@ -62,8 +62,17 @@ private module MissingXmlValidationConfig implements DataFlow::ConfigSig { */ module MissingXmlValidation = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelFlowSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** + * A source supported by the current threat model. + */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * The input argument to a call to `XmlReader.Create` where the input will not be validated against diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ReDoSQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ReDoSQuery.qll index 27f70a0d4e4..84d12fca0cc 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ReDoSQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ReDoSQuery.qll @@ -5,7 +5,7 @@ import csharp private import semmle.code.csharp.dataflow.DataFlow2 -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.text.RegularExpressions private import semmle.code.csharp.security.Sanitizers @@ -55,8 +55,15 @@ private module ReDoSConfig implements DataFlow::ConfigSig { */ module ReDoS = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * An expression that represents a regular expression with potential exponential behavior. diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/RegexInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/RegexInjectionQuery.qll index 89baeda92b6..501ede13f29 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/RegexInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/RegexInjectionQuery.qll @@ -4,7 +4,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.text.RegularExpressions private import semmle.code.csharp.security.Sanitizers @@ -54,8 +54,15 @@ private module RegexInjectionConfig implements DataFlow::ConfigSig { */ module RegexInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * A `pattern` argument to a construction of a `Regex`. diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ResourceInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ResourceInjectionQuery.qll index 336ca17ca75..56cb59001cd 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/ResourceInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/ResourceInjectionQuery.qll @@ -3,8 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote -private import semmle.code.csharp.security.dataflow.flowsources.Local +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.Data private import semmle.code.csharp.security.Sanitizers @@ -54,11 +53,24 @@ private module ResourceInjectionConfig implements DataFlow::ConfigSig { */ module ResourceInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } -/** A source of local user input. */ -class LocalSource extends Source instanceof LocalFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of local user input. + */ +deprecated class LocalSource extends DataFlow::Node instanceof LocalFlowSource { } + +private class AddLocalSource extends Source instanceof LocalFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** An argument to the `ConnectionString` property on a data connection class. */ class SqlConnectionStringSink extends Sink { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/SqlInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/SqlInjectionQuery.qll index 7500ac7a994..12c580381b9 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/SqlInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/SqlInjectionQuery.qll @@ -3,8 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote -private import semmle.code.csharp.security.dataflow.flowsources.Local +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.Sql private import semmle.code.csharp.security.Sanitizers private import semmle.code.csharp.dataflow.internal.ExternalFlow @@ -65,11 +64,24 @@ module SqlInjectionConfig implements DataFlow::ConfigSig { */ module SqlInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } -/** A source of local user input. */ -class LocalSource extends Source instanceof LocalFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of local user input. + */ +deprecated class LocalSource extends DataFlow::Node instanceof LocalFlowSource { } + +private class AddLocalSource extends Source instanceof LocalFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** An SQL expression passed to an API call that executes SQL. */ class SqlInjectionExprSink extends Sink { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/TaintedPathQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/TaintedPathQuery.qll index 005a9e96bfa..bbd32b58353 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/TaintedPathQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/TaintedPathQuery.qll @@ -5,7 +5,7 @@ import csharp private import semmle.code.csharp.controlflow.Guards -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.IO private import semmle.code.csharp.frameworks.system.Web private import semmle.code.csharp.security.Sanitizers @@ -56,8 +56,15 @@ private module TaintedPathConfig implements DataFlow::ConfigSig { */ module TaintedPath = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * A path argument to a `File` method call. diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/UnsafeDeserializationQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/UnsafeDeserializationQuery.qll index cf558b62c43..6de1305a11d 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/UnsafeDeserializationQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/UnsafeDeserializationQuery.qll @@ -6,7 +6,7 @@ import csharp private import semmle.code.csharp.serialization.Deserializers private import semmle.code.csharp.dataflow.TaintTracking2 -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources /** * A data flow source for unsafe deserialization vulnerabilities. @@ -48,7 +48,7 @@ abstract private class ConstructorOrStaticMethodSink extends Sink { } */ abstract class Sanitizer extends DataFlow::Node { } -private class RemoteSource extends Source instanceof RemoteFlowSource { } +private class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * DEPRECATED: Use `TaintToObjectMethodTracking` instead. diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll index 53b4cceb960..9a5ec46cb37 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll @@ -3,7 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.controlflow.Guards private import semmle.code.csharp.frameworks.Format private import semmle.code.csharp.frameworks.system.Web @@ -58,8 +58,15 @@ private module UrlRedirectConfig implements DataFlow::ConfigSig { */ module UrlRedirect = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** URL Redirection sinks defined through Models as Data. */ private class ExternalUrlRedirectExprSink extends Sink { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XMLEntityInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XMLEntityInjectionQuery.qll index e2d347a2268..7e7fd61fb1c 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XMLEntityInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XMLEntityInjectionQuery.qll @@ -3,7 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.System private import semmle.code.csharp.frameworks.system.text.RegularExpressions private import semmle.code.csharp.security.xml.InsecureXMLQuery as InsecureXml @@ -14,7 +14,7 @@ private import semmle.code.csharp.security.Sanitizers */ abstract class Source extends DataFlow::Node { } -private class RemoteSource extends Source instanceof RemoteFlowSource { } +private class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * A data flow sink for untrusted user input used in XML processing. diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XPathInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XPathInjectionQuery.qll index 57a0d6e9b50..1edddf45f56 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XPathInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XPathInjectionQuery.qll @@ -3,7 +3,7 @@ */ import csharp -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.frameworks.system.xml.XPath private import semmle.code.csharp.frameworks.system.Xml private import semmle.code.csharp.security.Sanitizers @@ -64,8 +64,15 @@ module XpathInjectionConfig implements DataFlow::ConfigSig { */ module XpathInjection = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** The `xpath` argument to an `XPathExpression.Compile(..)` call. */ class XPathExpressionCompileSink extends Sink { diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSQuery.qll index 1dea41c8a7c..b9fd47689f9 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSQuery.qll @@ -6,7 +6,7 @@ import csharp private import XSSSinks private import semmle.code.csharp.security.Sanitizers -private import semmle.code.csharp.security.dataflow.flowsources.Remote +private import semmle.code.csharp.security.dataflow.flowsources.FlowSources private import semmle.code.csharp.dataflow.DataFlow2 private import semmle.code.csharp.dataflow.TaintTracking2 @@ -179,8 +179,8 @@ module XssTrackingConfig implements DataFlow::ConfigSig { module XssTracking = TaintTracking::Global; -/** A source of remote user input. */ -private class RemoteSource extends Source instanceof RemoteFlowSource { } +/** A source supported by the current threat model. */ +private class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } private class SimpleTypeSanitizer extends Sanitizer, SimpleTypeSanitizedExpr { } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/FlowSources.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/FlowSources.qll index 6da08298fb9..a5ada1cbaf8 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/FlowSources.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/FlowSources.qll @@ -14,6 +14,9 @@ abstract class SourceNode extends DataFlow::Node { * Gets a string that represents the source kind with respect to threat modeling. */ abstract string getThreatModel(); + + /** Gets a string that describes the type of this flow source. */ + abstract string getSourceType(); } /** diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Local.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Local.qll index 7ee1d4b744c..121f53c4929 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Local.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Local.qll @@ -9,8 +9,7 @@ private import semmle.code.csharp.security.dataflow.flowsources.FlowSources /** A data flow source of local data. */ abstract class LocalFlowSource extends SourceNode { - /** Gets a string that describes the type of this local flow source. */ - abstract string getSourceType(); + override string getSourceType() { result = "local flow source" } override string getThreatModel() { result = "local" } } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll index 07c230c19c2..dc2fb36c47a 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll @@ -17,8 +17,7 @@ private import semmle.code.csharp.security.dataflow.flowsources.FlowSources /** A data flow source of remote user input. */ abstract class RemoteFlowSource extends SourceNode { - /** Gets a string that describes the type of this remote flow source. */ - abstract string getSourceType(); + override string getSourceType() { result = "remote flow source" } override string getThreatModel() { result = "remote" } } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Stored.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Stored.qll index 95df5284b1d..2d2ecd0bccb 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Stored.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Stored.qll @@ -21,6 +21,8 @@ abstract class StoredFlowSource extends SourceNode { */ abstract class DatabaseInputSource extends StoredFlowSource { override string getThreatModel() { result = "database" } + + override string getSourceType() { result = "database input" } } /** @@ -76,4 +78,6 @@ class FileStreamStoredFlowSource extends StoredFlowSource { FileStreamStoredFlowSource() { sourceNode(this, "file") } override string getThreatModel() { result = "file" } + + override string getSourceType() { result = "file stream" } } diff --git a/csharp/ql/src/Security Features/CWE-089/SqlInjection.ql b/csharp/ql/src/Security Features/CWE-089/SqlInjection.ql index e3fa7f80bd7..d4d1287561f 100644 --- a/csharp/ql/src/Security Features/CWE-089/SqlInjection.ql +++ b/csharp/ql/src/Security Features/CWE-089/SqlInjection.ql @@ -14,14 +14,9 @@ import csharp import semmle.code.csharp.security.dataflow.SqlInjectionQuery import SqlInjection::PathGraph -import semmle.code.csharp.security.dataflow.flowsources.Remote -import semmle.code.csharp.security.dataflow.flowsources.Local +import semmle.code.csharp.security.dataflow.flowsources.FlowSources -string getSourceType(DataFlow::Node node) { - result = node.(RemoteFlowSource).getSourceType() - or - result = node.(LocalFlowSource).getSourceType() -} +string getSourceType(DataFlow::Node node) { result = node.(SourceNode).getSourceType() } from SqlInjection::PathNode source, SqlInjection::PathNode sink where SqlInjection::flowPath(source, sink) diff --git a/csharp/ql/src/Security Features/CWE-091/XMLInjection.ql b/csharp/ql/src/Security Features/CWE-091/XMLInjection.ql index 7402a45edde..042e2aa9f17 100644 --- a/csharp/ql/src/Security Features/CWE-091/XMLInjection.ql +++ b/csharp/ql/src/Security Features/CWE-091/XMLInjection.ql @@ -12,7 +12,7 @@ */ import csharp -import semmle.code.csharp.security.dataflow.flowsources.Remote +import semmle.code.csharp.security.dataflow.flowsources.FlowSources import semmle.code.csharp.frameworks.system.Xml import XmlInjection::PathGraph @@ -20,7 +20,7 @@ import XmlInjection::PathGraph * A taint-tracking configuration for untrusted user input used in XML. */ module XmlInjectionConfig implements DataFlow::ConfigSig { - predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } + predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource } predicate isSink(DataFlow::Node sink) { exists(MethodCall mc | diff --git a/csharp/ql/src/Security Features/CWE-114/AssemblyPathInjection.ql b/csharp/ql/src/Security Features/CWE-114/AssemblyPathInjection.ql index daaaba7517d..a6150b53798 100644 --- a/csharp/ql/src/Security Features/CWE-114/AssemblyPathInjection.ql +++ b/csharp/ql/src/Security Features/CWE-114/AssemblyPathInjection.ql @@ -13,7 +13,7 @@ */ import csharp -import semmle.code.csharp.security.dataflow.flowsources.Remote +import semmle.code.csharp.security.dataflow.flowsources.FlowSources import semmle.code.csharp.commons.Util import AssemblyPathInjection::PathGraph @@ -22,7 +22,7 @@ import AssemblyPathInjection::PathGraph */ module AssemblyPathInjectionConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { - source instanceof RemoteFlowSource or + source instanceof ThreatModelFlowSource or source.asExpr() = any(MainMethod main).getParameter(0).getAnAccess() } diff --git a/csharp/ql/src/Security Features/CWE-134/UncontrolledFormatString.ql b/csharp/ql/src/Security Features/CWE-134/UncontrolledFormatString.ql index e8b9aa0a53f..657fdd0e183 100644 --- a/csharp/ql/src/Security Features/CWE-134/UncontrolledFormatString.ql +++ b/csharp/ql/src/Security Features/CWE-134/UncontrolledFormatString.ql @@ -12,16 +12,13 @@ */ import csharp -import semmle.code.csharp.security.dataflow.flowsources.Remote -import semmle.code.csharp.security.dataflow.flowsources.Local +import semmle.code.csharp.security.dataflow.flowsources.FlowSources import semmle.code.csharp.frameworks.Format import FormatString::PathGraph module FormatStringConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { - source instanceof RemoteFlowSource - or - source instanceof LocalFlowSource + source instanceof ThreatModelFlowSource or source instanceof LocalFlowSource } predicate isSink(DataFlow::Node sink) { @@ -31,11 +28,7 @@ module FormatStringConfig implements DataFlow::ConfigSig { module FormatString = TaintTracking::Global; -string getSourceType(DataFlow::Node node) { - result = node.(RemoteFlowSource).getSourceType() - or - result = node.(LocalFlowSource).getSourceType() -} +string getSourceType(DataFlow::Node node) { result = node.(SourceNode).getSourceType() } from FormatString::PathNode source, FormatString::PathNode sink where FormatString::flowPath(source, sink) diff --git a/csharp/ql/src/change-notes/2024-02-06-threat-models.md b/csharp/ql/src/change-notes/2024-02-06-threat-models.md new file mode 100644 index 00000000000..69ac4e4dc17 --- /dev/null +++ b/csharp/ql/src/change-notes/2024-02-06-threat-models.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Most data flow queries that track flow from *remote* flow sources now use the current *threat model* configuration instead. This doesn't lead to any changes in the produced alerts (as the default configuration is *remote* flow sources) unless the threat model configuration is changed. The changed queries are `cs/code-injection`, `cs/command-line-injection`, `cs/user-controlled-bypass`, `cs/count-untrusted-data-external-api`, `cs/untrusted-data-to-external-api`, `cs/ldap-injection`, `cs/log-forging`, `cs/xml/missing-validation`, `cs/redos`, `cs/regex-injection`, `cs/resource-injection`, `cs/sql-injection`, `cs/path-injection`, `cs/unsafe-deserialization-untrusted-input`, `cs/web/unvalidated-url-redirection`, `cs/xml/insecure-dtd-handling`, `cs/xml/xpath-injection`, `cs/web/xss`, and `cs/uncontrolled-format-string`. \ No newline at end of file diff --git a/csharp/ql/src/experimental/CWE-099/TaintedWebClientLib.qll b/csharp/ql/src/experimental/CWE-099/TaintedWebClientLib.qll index 3810ff6f76a..e3459dfb1ac 100644 --- a/csharp/ql/src/experimental/CWE-099/TaintedWebClientLib.qll +++ b/csharp/ql/src/experimental/CWE-099/TaintedWebClientLib.qll @@ -1,7 +1,7 @@ import csharp import semmle.code.csharp.frameworks.system.Net import semmle.code.csharp.frameworks.System -import semmle.code.csharp.security.dataflow.flowsources.Remote +import semmle.code.csharp.security.dataflow.flowsources.FlowSources import semmle.code.csharp.security.Sanitizers //If this leaves experimental this should probably go in semmle.code.csharp.frameworks.system.Net @@ -68,8 +68,15 @@ private module TaintedWebClientConfig implements DataFlow::ConfigSig { */ module TaintedWebClient = TaintTracking::Global; -/** A source of remote user input. */ -class RemoteSource extends Source instanceof RemoteFlowSource { } +/** + * DEPRECATED: Use `ThreatModelSource` instead. + * + * A source of remote user input. + */ +deprecated class RemoteSource extends DataFlow::Node instanceof RemoteFlowSource { } + +/** A source supported by the current threat model. */ +class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * A path argument to a `WebClient` method call that has an address argument. diff --git a/csharp/ql/src/experimental/CWE-918/RequestForgery.qll b/csharp/ql/src/experimental/CWE-918/RequestForgery.qll index 29d4fa9094b..e1c6875d952 100644 --- a/csharp/ql/src/experimental/CWE-918/RequestForgery.qll +++ b/csharp/ql/src/experimental/CWE-918/RequestForgery.qll @@ -5,7 +5,7 @@ module RequestForgery { import semmle.code.csharp.frameworks.System import semmle.code.csharp.frameworks.system.Web import semmle.code.csharp.frameworks.Format - import semmle.code.csharp.security.dataflow.flowsources.Remote + import semmle.code.csharp.security.dataflow.flowsources.FlowSources /** * A data flow source for server side request forgery vulnerabilities. @@ -91,10 +91,9 @@ module RequestForgery { module RequestForgeryFlow = DataFlow::Global; /** - * A remote data flow source taken as a source - * for Server Side Request Forgery(SSRF) Vulnerabilities. + * A dataflow source for Server Side Request Forgery(SSRF) Vulnerabilities. */ - private class RemoteFlowSourceAsSource extends Source instanceof RemoteFlowSource { } + private class ThreatModelSource extends Source instanceof ThreatModelFlowSource { } /** * An url argument to a `HttpRequestMessage` constructor call diff --git a/csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatString.ext.yml b/csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatString.ext.yml new file mode 100644 index 00000000000..82f107ae1d7 --- /dev/null +++ b/csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatString.ext.yml @@ -0,0 +1,7 @@ +extensions: + + - addsTo: + pack: codeql/threat-models + extensible: threatModelConfiguration + data: + - ["local", true, 0] \ No newline at end of file