@@ -16,47 +16,50 @@ import semmle.python.Concepts
16
16
*/
17
17
module NoSqlInjection {
18
18
private newtype TFlowState =
19
- TStringInput ( ) or
20
- TInterpretedStringInput ( )
19
+ TString ( ) or
20
+ TDict ( )
21
21
22
- /** A flow state, tracking the structure of the input . */
22
+ /** A flow state, tracking the structure of the data . */
23
23
abstract class FlowState extends TFlowState {
24
24
/** Gets a textual representation of this element. */
25
25
abstract string toString ( ) ;
26
26
}
27
27
28
- /** A state where input is only a string. */
29
- class StringInput extends FlowState , TStringInput {
30
- override string toString ( ) { result = "StringInput " }
28
+ /** A state where the tracked data is only a string. */
29
+ class String extends FlowState , TString {
30
+ override string toString ( ) { result = "String " }
31
31
}
32
32
33
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.
34
+ * A state where the tracked data has been converted to
35
+ * a dictionary.
36
+ *
37
+ * We include cases where data represent JSON objects, so
38
+ * it could actually still be just a string. It could
39
+ * also contain query operators, or even JavaScript code.
37
40
*/
38
- class InterpretedStringInput extends FlowState , TInterpretedStringInput {
39
- override string toString ( ) { result = "InterpretedStringInput " }
41
+ class Dict extends FlowState , TDict {
42
+ override string toString ( ) { result = "Dict " }
40
43
}
41
44
42
45
/** A source allowing string inputs. */
43
46
abstract class StringSource extends DataFlow:: Node { }
44
47
45
- /** A source of interpreted strings . */
46
- abstract class InterpretedStringSource extends DataFlow:: Node { }
48
+ /** A source of allowing dictionaries . */
49
+ abstract class DictSource extends DataFlow:: Node { }
47
50
48
51
/** A sink vulnerable to user controlled strings. */
49
52
abstract class StringSink extends DataFlow:: Node { }
50
53
51
- /** A sink vulnerable to user controlled interpreted strings . */
52
- abstract class InterpretedStringSink extends DataFlow:: Node { }
54
+ /** A sink vulnerable to user controlled dictionaries . */
55
+ abstract class DictSink extends DataFlow:: Node { }
53
56
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 . */
57
+ /** A data flow node where a string is converted into a dictionary . */
58
+ abstract class StringToDictConversion extends DataFlow:: Node {
59
+ /** Gets the argument that specifies the string to be converted . */
57
60
abstract DataFlow:: Node getAnInput ( ) ;
58
61
59
- /** Gets the result of interpreting the string . */
62
+ /** Gets the resulting dictionary . */
60
63
abstract DataFlow:: Node getOutput ( ) ;
61
64
}
62
65
@@ -72,22 +75,22 @@ module NoSqlInjection {
72
75
}
73
76
}
74
77
75
- /** A NoSQL query that is vulnerable to user controlled InterpretedStringionaries . */
76
- class NoSqlExecutionAsInterpretedStringSink extends InterpretedStringSink {
77
- NoSqlExecutionAsInterpretedStringSink ( ) { this = any ( NoSqlExecution noSqlExecution ) .getQuery ( ) }
78
+ /** A NoSQL query that is vulnerable to user controlled dictionaries . */
79
+ class NoSqlExecutionAsDictSink extends DictSink {
80
+ NoSqlExecutionAsDictSink ( ) { this = any ( NoSqlExecution noSqlExecution ) .getQuery ( ) }
78
81
}
79
82
80
- /** A JSON decoding converts a string to a Dictionary . */
81
- class JsonDecoding extends Decoding , StringInterpretation {
83
+ /** A JSON decoding converts a string to a dictionary . */
84
+ class JsonDecoding extends Decoding , StringToDictConversion {
82
85
JsonDecoding ( ) { this .getFormat ( ) = "JSON" }
83
86
84
87
override DataFlow:: Node getAnInput ( ) { result = Decoding .super .getAnInput ( ) }
85
88
86
89
override DataFlow:: Node getOutput ( ) { result = Decoding .super .getOutput ( ) }
87
90
}
88
91
89
- /** A NoSQL decoding interprets a string. */
90
- class NoSqlDecoding extends Decoding , StringInterpretation {
92
+ /** A NoSQL decoding interprets a string as a dictionary . */
93
+ class NoSqlDecoding extends Decoding , StringToDictConversion {
91
94
NoSqlDecoding ( ) { this .getFormat ( ) = "NoSQL" }
92
95
93
96
override DataFlow:: Node getAnInput ( ) { result = Decoding .super .getAnInput ( ) }
0 commit comments