@@ -17,7 +17,7 @@ import semmle.python.Concepts
1717module NoSqlInjection {
1818 private newtype TFlowState =
1919 TStringInput ( ) or
20- TDictInput ( )
20+ TInterpretedStringInput ( )
2121
2222 /** A flow state, tracking the structure of the input. */
2323 abstract class FlowState extends TFlowState {
@@ -30,29 +30,33 @@ module NoSqlInjection {
3030 override string toString ( ) { result = "StringInput" }
3131 }
3232
33- /** A state where input is a dictionary. */
34- class DictInput extends FlowState , TDictInput {
35- override string toString ( ) { result = "DictInput" }
33+ /**
34+ * A state where input is a string that has been interpreted.
35+ * For instance, it could have been turned into a dictionary,
36+ * or evaluated as javascript code.
37+ */
38+ class InterpretedStringInput extends FlowState , TInterpretedStringInput {
39+ override string toString ( ) { result = "InterpretedStringInput" }
3640 }
3741
3842 /** A source allowing string inputs. */
3943 abstract class StringSource extends DataFlow:: Node { }
4044
41- /** A source allowing dictionary inputs . */
42- abstract class DictSource extends DataFlow:: Node { }
45+ /** A source of interpreted strings . */
46+ abstract class InterpretedStringSource extends DataFlow:: Node { }
4347
4448 /** A sink vulnerable to user controlled strings. */
4549 abstract class StringSink extends DataFlow:: Node { }
4650
47- /** A sink vulnerable to user controlled dictionaries . */
48- abstract class DictSink extends DataFlow:: Node { }
51+ /** A sink vulnerable to user controlled interpreted strings . */
52+ abstract class InterpretedStringSink extends DataFlow:: Node { }
4953
50- /** A data flow node where a string is converted into a dictionary . */
51- abstract class StringToDictConversion extends DataFlow:: Node {
52- /** Gets the argument that specifies the string to be converted . */
54+ /** A data flow node where a string is being interpreted . */
55+ abstract class StringInterpretation extends DataFlow:: Node {
56+ /** Gets the argument that specifies the string to be interpreted . */
5357 abstract DataFlow:: Node getAnInput ( ) ;
5458
55- /** Gets the resulting dictionary . */
59+ /** Gets the result of interpreting the string . */
5660 abstract DataFlow:: Node getOutput ( ) ;
5761 }
5862
@@ -68,14 +72,23 @@ module NoSqlInjection {
6872 }
6973 }
7074
71- /** A NoSQL query that is vulnerable to user controlled dictionaries . */
72- class NoSqlExecutionAsDictSink extends DictSink {
73- NoSqlExecutionAsDictSink ( ) { this = any ( NoSqlExecution noSqlExecution ) .getQuery ( ) }
75+ /** A NoSQL query that is vulnerable to user controlled InterpretedStringionaries . */
76+ class NoSqlExecutionAsInterpretedStringSink extends InterpretedStringSink {
77+ NoSqlExecutionAsInterpretedStringSink ( ) { this = any ( NoSqlExecution noSqlExecution ) .getQuery ( ) }
7478 }
7579
76- /** A JSON decoding converts a string to a dictionary. */
77- class JsonDecoding extends Decoding , StringToDictConversion {
78- JsonDecoding ( ) { this .getFormat ( ) in [ "JSON" , "NoSQL" ] }
80+ /** A JSON decoding converts a string to a Dictionary. */
81+ class JsonDecoding extends Decoding , StringInterpretation {
82+ JsonDecoding ( ) { this .getFormat ( ) = "JSON" }
83+
84+ override DataFlow:: Node getAnInput ( ) { result = Decoding .super .getAnInput ( ) }
85+
86+ override DataFlow:: Node getOutput ( ) { result = Decoding .super .getOutput ( ) }
87+ }
88+
89+ /** A NoSQL decoding interprets a string. */
90+ class NoSqlDecoding extends Decoding , StringInterpretation {
91+ NoSqlDecoding ( ) { this .getFormat ( ) = "NoSQL" }
7992
8093 override DataFlow:: Node getAnInput ( ) { result = Decoding .super .getAnInput ( ) }
8194
0 commit comments