@@ -8,20 +8,57 @@ import javascript
8
8
private import semmle.javascript.security.dataflow.CodeInjectionCustomizations
9
9
10
10
module HardcodedDataInterpretedAsCode {
11
+ private newtype TFlowState =
12
+ TUnmodified ( ) or
13
+ TModified ( )
14
+
15
+ /** A flow state to associate with a tracked value. */
16
+ class FlowState extends TFlowState {
17
+ /** Gets a string representation fo this flow state */
18
+ string toString ( ) {
19
+ this = TUnmodified ( ) and result = "unmodified"
20
+ or
21
+ this = TModified ( ) and result = "modified"
22
+ }
23
+
24
+ deprecated DataFlow:: FlowLabel toFlowLabel ( ) {
25
+ this = TUnmodified ( ) and result .isData ( )
26
+ or
27
+ this = TModified ( ) and result .isTaint ( )
28
+ }
29
+ }
30
+
31
+ /** Predicates for working with flow states. */
32
+ module FlowState {
33
+ deprecated FlowState fromFlowLabel ( DataFlow:: FlowLabel label ) { result .toFlowLabel ( ) = label }
34
+
35
+ /** An unmodified value originating from a string constant. */
36
+ FlowState unmodified ( ) { result = TUnmodified ( ) }
37
+
38
+ /** A value which has undergone some transformation, such as hex decoding. */
39
+ FlowState modified ( ) { result = TModified ( ) }
40
+ }
41
+
11
42
/**
12
43
* A data flow source for hard-coded data.
13
44
*/
14
45
abstract class Source extends DataFlow:: Node {
15
- /** Gets a flow label for which this is a source. */
16
- DataFlow:: FlowLabel getLabel ( ) { result .isData ( ) }
46
+ /** Gets a flow state for which this is a source. */
47
+ FlowState getAFlowState ( ) { result = FlowState:: unmodified ( ) }
48
+
49
+ /** DEPRECATED. Use `getAFlowState()` instead. */
50
+ deprecated DataFlow:: FlowLabel getLabel ( ) { result = this .getAFlowState ( ) .toFlowLabel ( ) }
17
51
}
18
52
19
53
/**
20
54
* A data flow sink for code injection.
21
55
*/
22
56
abstract class Sink extends DataFlow:: Node {
23
- /** Gets a flow label for which this is a sink. */
24
- abstract DataFlow:: FlowLabel getLabel ( ) ;
57
+ /** Gets a flow state for which this is a sink. */
58
+ FlowState getAFlowState ( ) { result = FlowState:: modified ( ) }
59
+
60
+ /** DEPRECATED. Use `getAFlowState()` instead. */
61
+ deprecated DataFlow:: FlowLabel getLabel ( ) { result = this .getAFlowState ( ) .toFlowLabel ( ) }
25
62
26
63
/** Gets a description of what kind of sink this is. */
27
64
abstract string getKind ( ) ;
@@ -50,7 +87,7 @@ module HardcodedDataInterpretedAsCode {
50
87
* A code injection sink; hard-coded data should not flow here.
51
88
*/
52
89
private class DefaultCodeInjectionSink extends Sink instanceof CodeInjection:: Sink {
53
- override DataFlow :: FlowLabel getLabel ( ) { result . isTaint ( ) }
90
+ override FlowState getAFlowState ( ) { result = FlowState :: modified ( ) }
54
91
55
92
override string getKind ( ) { result = "Code" }
56
93
}
@@ -61,7 +98,7 @@ module HardcodedDataInterpretedAsCode {
61
98
private class RequireArgumentSink extends Sink {
62
99
RequireArgumentSink ( ) { this = any ( Require r ) .getAnArgument ( ) .flow ( ) }
63
100
64
- override DataFlow :: FlowLabel getLabel ( ) { result . isDataOrTaint ( ) }
101
+ override FlowState getAFlowState ( ) { result = [ FlowState :: modified ( ) , FlowState :: unmodified ( ) ] }
65
102
66
103
override string getKind ( ) { result = "An import path" }
67
104
}
0 commit comments