@@ -19,6 +19,15 @@ class PostValidation extends DataFlow::FlowState {
19
19
PostValidation ( ) { this = "PostValidation" }
20
20
}
21
21
22
+ /**
23
+ * A state signifying if a logical validation has been performed or not.
24
+ */
25
+ private newtype ValidationState =
26
+ // A state signifying that a logical validation has not been performed.
27
+ PreValidationState ( ) or
28
+ // A state signifying that a logical validation has been performed.
29
+ PostValidationState ( )
30
+
22
31
/**
23
32
* A taint-tracking configuration for detecting "Unicode transformation mishandling" vulnerabilities.
24
33
*
@@ -29,20 +38,27 @@ class PostValidation extends DataFlow::FlowState {
29
38
deprecated class Configuration extends TaintTracking:: Configuration {
30
39
Configuration ( ) { this = "UnicodeBypassValidation" }
31
40
41
+ private ValidationState convertState ( DataFlow:: FlowState state ) {
42
+ state instanceof PreValidation and result = PreValidationState ( )
43
+ or
44
+ state instanceof PostValidation and result = PostValidationState ( )
45
+ }
46
+
32
47
override predicate isSource ( DataFlow:: Node source , DataFlow:: FlowState state ) {
33
- UnicodeBypassValidationConfig:: isSource ( source , state )
48
+ UnicodeBypassValidationConfig:: isSource ( source , this . convertState ( state ) )
34
49
}
35
50
36
51
override predicate isAdditionalTaintStep (
37
52
DataFlow:: Node nodeFrom , DataFlow:: FlowState stateFrom , DataFlow:: Node nodeTo ,
38
53
DataFlow:: FlowState stateTo
39
54
) {
40
- UnicodeBypassValidationConfig:: isAdditionalFlowStep ( nodeFrom , stateFrom , nodeTo , stateTo )
55
+ UnicodeBypassValidationConfig:: isAdditionalFlowStep ( nodeFrom , this .convertState ( stateFrom ) , nodeTo ,
56
+ this .convertState ( stateTo ) )
41
57
}
42
58
43
59
/* A Unicode Tranformation (Unicode tranformation) is considered a sink when the algorithm used is either NFC or NFKC. */
44
60
override predicate isSink ( DataFlow:: Node sink , DataFlow:: FlowState state ) {
45
- UnicodeBypassValidationConfig:: isSink ( sink , state )
61
+ UnicodeBypassValidationConfig:: isSink ( sink , this . convertState ( state ) )
46
62
}
47
63
}
48
64
@@ -53,15 +69,14 @@ deprecated class Configuration extends TaintTracking::Configuration {
53
69
* to track the requirement that a logical validation has been performed before the Unicode Transformation.
54
70
*/
55
71
private module UnicodeBypassValidationConfig implements DataFlow:: StateConfigSig {
56
- class FlowState = DataFlow :: FlowState ;
72
+ class FlowState = ValidationState ;
57
73
58
- predicate isSource ( DataFlow:: Node source , DataFlow :: FlowState state ) {
59
- source instanceof RemoteFlowSource and state instanceof PreValidation
74
+ predicate isSource ( DataFlow:: Node source , FlowState state ) {
75
+ source instanceof RemoteFlowSource and state = PreValidationState ( )
60
76
}
61
77
62
78
predicate isAdditionalFlowStep (
63
- DataFlow:: Node nodeFrom , DataFlow:: FlowState stateFrom , DataFlow:: Node nodeTo ,
64
- DataFlow:: FlowState stateTo
79
+ DataFlow:: Node nodeFrom , FlowState stateFrom , DataFlow:: Node nodeTo , FlowState stateTo
65
80
) {
66
81
(
67
82
exists ( Escaping escaping | nodeFrom = escaping .getAnInput ( ) and nodeTo = escaping .getOutput ( ) )
@@ -102,12 +117,12 @@ private module UnicodeBypassValidationConfig implements DataFlow::StateConfigSig
102
117
nodeTo = cn
103
118
)
104
119
) and
105
- stateFrom instanceof PreValidation and
106
- stateTo instanceof PostValidation
120
+ stateFrom = PreValidationState ( ) and
121
+ stateTo = PostValidationState ( )
107
122
}
108
123
109
124
/* A Unicode Tranformation (Unicode tranformation) is considered a sink when the algorithm used is either NFC or NFKC. */
110
- predicate isSink ( DataFlow:: Node sink , DataFlow :: FlowState state ) {
125
+ predicate isSink ( DataFlow:: Node sink , FlowState state ) {
111
126
(
112
127
exists ( DataFlow:: CallNode cn |
113
128
cn .getMethodName ( ) = "unicode_normalize" and
@@ -145,7 +160,7 @@ private module UnicodeBypassValidationConfig implements DataFlow::StateConfigSig
145
160
sink = cn .getArgument ( 0 )
146
161
)
147
162
) and
148
- state instanceof PostValidation
163
+ state = PostValidationState ( )
149
164
}
150
165
}
151
166
0 commit comments