@@ -8,20 +8,57 @@ import javascript
88private import semmle.javascript.security.dataflow.CodeInjectionCustomizations
99
1010module 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+
1142 /**
1243 * A data flow source for hard-coded data.
1344 */
1445 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 ( ) }
1751 }
1852
1953 /**
2054 * A data flow sink for code injection.
2155 */
2256 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 ( ) }
2562
2663 /** Gets a description of what kind of sink this is. */
2764 abstract string getKind ( ) ;
@@ -50,7 +87,7 @@ module HardcodedDataInterpretedAsCode {
5087 * A code injection sink; hard-coded data should not flow here.
5188 */
5289 private class DefaultCodeInjectionSink extends Sink instanceof CodeInjection:: Sink {
53- override DataFlow :: FlowLabel getLabel ( ) { result . isTaint ( ) }
90+ override FlowState getAFlowState ( ) { result = FlowState :: modified ( ) }
5491
5592 override string getKind ( ) { result = "Code" }
5693 }
@@ -61,7 +98,7 @@ module HardcodedDataInterpretedAsCode {
6198 private class RequireArgumentSink extends Sink {
6299 RequireArgumentSink ( ) { this = any ( Require r ) .getAnArgument ( ) .flow ( ) }
63100
64- override DataFlow :: FlowLabel getLabel ( ) { result . isDataOrTaint ( ) }
101+ override FlowState getAFlowState ( ) { result = [ FlowState :: modified ( ) , FlowState :: unmodified ( ) ] }
65102
66103 override string getKind ( ) { result = "An import path" }
67104 }
0 commit comments