@@ -27,11 +27,6 @@ module UnsafeDeserialization {
2727 abstract string getSinkType ( ) ;
2828 }
2929
30- /**
31- * A sanitizer for Unsafe Deserialization vulnerabilities.
32- */
33- abstract class Sanitizer extends DataFlow:: Node { }
34-
3530 /** A source of user input, considered as a flow source for unsafe deserialization. */
3631 class FlowSourceAsSource extends Source instanceof SourceNode {
3732 override string getSourceType ( ) { result = SourceNode .super .getSourceType ( ) }
@@ -42,14 +37,16 @@ module UnsafeDeserialization {
4237 * (lowercase) matches `fullTypeName`. Handles both `New-Object TypeName` and
4338 * `[TypeName]::new()` patterns.
4439 */
45- private predicate objectCreationMatchesType (
46- DataFlow:: ObjectCreationNode ocn , string fullTypeName
47- ) {
40+ private predicate objectCreationMatchesType ( DataFlow:: ObjectCreationNode ocn , string fullTypeName ) {
4841 // New-Object TypeName: getLowerCaseConstructedTypeName() returns the full qualified name
4942 ocn .getLowerCaseConstructedTypeName ( ) = fullTypeName
5043 or
5144 // [TypeName]::new(): access the qualifier TypeNameExpr for the full qualified name
52- ocn .getExprNode ( ) .getExpr ( ) .( ConstructorCall ) .getQualifier ( ) .( TypeNameExpr )
45+ ocn .getExprNode ( )
46+ .getExpr ( )
47+ .( ConstructorCall )
48+ .getQualifier ( )
49+ .( TypeNameExpr )
5350 .getPossiblyQualifiedName ( ) = fullTypeName
5451 }
5552
@@ -106,20 +103,28 @@ module UnsafeDeserialization {
106103 }
107104
108105 /**
109- * An argument to a BinaryFormatter deserialization method call, including
110- * Deserialize, UnsafeDeserialize, and UnsafeDeserializeMethodResponse.
106+ * A BinaryFormatter deserialization method call, including Deserialize, UnsafeDeserialize,
107+ * and UnsafeDeserializeMethodResponse.
111108 */
112- class BinaryFormatterDeserializeSink extends Sink {
113- BinaryFormatterDeserializeSink ( ) {
114- exists ( DataFlow:: ObjectCreationNode ocn , DataFlow :: CallNode cn |
115- cn .getQualifier ( ) .getALocalSource ( ) = ocn and
109+ class BinaryFormatterDeserializeCall extends DataFlow :: CallNode {
110+ BinaryFormatterDeserializeCall ( ) {
111+ exists ( DataFlow:: ObjectCreationNode ocn |
112+ this .getQualifier ( ) .getALocalSource ( ) = ocn and
116113 objectCreationMatchesType ( ocn ,
117114 "system.runtime.serialization.formatters.binary.binaryformatter" ) and
118- cn .getLowerCaseName ( ) =
119- [ "deserialize" , "unsafedeserialize" , "unsafedeserializemethodresponse" ] and
120- cn .getAnArgument ( ) = this
115+ this .getLowerCaseName ( ) =
116+ [ "deserialize" , "unsafedeserialize" , "unsafedeserializemethodresponse" ]
121117 )
122118 }
119+ }
120+
121+ /**
122+ * An input argument to a BinaryFormatter deserialization method call.
123+ */
124+ class BinaryFormatterDeserializeSink extends Sink {
125+ BinaryFormatterDeserializeSink ( ) {
126+ exists ( BinaryFormatterDeserializeCall cn | cn .getAnArgument ( ) = this )
127+ }
123128
124129 override string getSinkType ( ) { result = "call to BinaryFormatter.Deserialize" }
125130 }
@@ -167,9 +172,7 @@ module UnsafeDeserialization {
167172 )
168173 }
169174
170- override string getSinkType ( ) {
171- result = "call to [" + typeName + "]::" + methodName
172- }
175+ override string getSinkType ( ) { result = "call to [" + typeName + "]::" + methodName }
173176 }
174177
175178 /**
0 commit comments