@@ -80,3 +80,123 @@ module PathInjection {
8080 NormalizedUnchecked ( ) { this = "NormalizedUnchecked" }
8181 }
8282}
83+
84+ // ---------------------------------------------------------------------------
85+ // Old, deprecated code
86+ // ---------------------------------------------------------------------------
87+ private import semmle.python.dataflow.new.DataFlow2
88+ private import semmle.python.dataflow.new.TaintTracking2
89+ private import ChainedConfigs12
90+ import PathInjectionCustomizations:: PathInjection
91+
92+ // ---------------------------------------------------------------------------
93+ // Case 1. The path is never normalized.
94+ // ---------------------------------------------------------------------------
95+ /**
96+ * DEPRECATED: Use `PathInjection::Configuration` instead
97+ *
98+ * Configuration to find paths from sources to sinks that contain no normalization.
99+ */
100+ deprecated class PathNotNormalizedConfiguration extends TaintTracking:: Configuration {
101+ PathNotNormalizedConfiguration ( ) { this = "PathNotNormalizedConfiguration" }
102+
103+ override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
104+
105+ override predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
106+
107+ override predicate isSanitizer ( DataFlow:: Node node ) {
108+ node instanceof Sanitizer
109+ or
110+ node instanceof Path:: PathNormalization
111+ }
112+
113+ override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
114+ guard instanceof SanitizerGuard
115+ }
116+ }
117+
118+ /**
119+ * DEPRECATED: Use `PathInjection::Configuration` instead
120+ *
121+ * Holds if there is a path injection from source to sink, where the (python) path is
122+ * not normalized.
123+ */
124+ deprecated predicate pathNotNormalized ( CustomPathNode source , CustomPathNode sink ) {
125+ any ( PathNotNormalizedConfiguration config ) .hasFlowPath ( source .asNode1 ( ) , sink .asNode1 ( ) )
126+ }
127+
128+ // ---------------------------------------------------------------------------
129+ // Case 2. The path is normalized at least once, but never checked afterwards.
130+ // ---------------------------------------------------------------------------
131+ /**
132+ * DEPRECATED: Use `PathInjection::Configuration` instead
133+ *
134+ * Configuration to find paths from sources to normalizations that contain no prior normalizations.
135+ */
136+ deprecated class FirstNormalizationConfiguration extends TaintTracking:: Configuration {
137+ FirstNormalizationConfiguration ( ) { this = "FirstNormalizationConfiguration" }
138+
139+ override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
140+
141+ override predicate isSink ( DataFlow:: Node sink ) { sink instanceof Path:: PathNormalization }
142+
143+ override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
144+
145+ override predicate isSanitizerOut ( DataFlow:: Node node ) { node instanceof Path:: PathNormalization }
146+
147+ override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
148+ guard instanceof SanitizerGuard
149+ }
150+ }
151+
152+ /**
153+ * DEPRECATED: Use `PathInjection::Configuration` instead
154+ *
155+ * Configuration to find paths from normalizations to sinks that do not go through a check.
156+ */
157+ deprecated class NormalizedPathNotCheckedConfiguration extends TaintTracking2:: Configuration {
158+ NormalizedPathNotCheckedConfiguration ( ) { this = "NormalizedPathNotCheckedConfiguration" }
159+
160+ override predicate isSource ( DataFlow:: Node source ) { source instanceof Path:: PathNormalization }
161+
162+ override predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
163+
164+ override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
165+
166+ override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
167+ guard instanceof Path:: SafeAccessCheck
168+ or
169+ guard instanceof SanitizerGuard
170+ }
171+ }
172+
173+ /**
174+ * DEPRECATED: Use `PathInjection::Configuration` instead
175+ *
176+ * Holds if there is a path injection from source to sink, where the (python) path is
177+ * normalized at least once, but never checked afterwards.
178+ */
179+ deprecated predicate pathNotCheckedAfterNormalization ( CustomPathNode source , CustomPathNode sink ) {
180+ exists (
181+ FirstNormalizationConfiguration config , DataFlow:: PathNode mid1 , DataFlow2:: PathNode mid2 ,
182+ NormalizedPathNotCheckedConfiguration config2
183+ |
184+ config .hasFlowPath ( source .asNode1 ( ) , mid1 ) and
185+ config2 .hasFlowPath ( mid2 , sink .asNode2 ( ) ) and
186+ mid1 .getNode ( ) .asCfgNode ( ) = mid2 .getNode ( ) .asCfgNode ( )
187+ )
188+ }
189+
190+ // ---------------------------------------------------------------------------
191+ // Query: Either case 1 or case 2.
192+ // ---------------------------------------------------------------------------
193+ /**
194+ * DEPRECATED: Use `PathInjection::Configuration` instead
195+ *
196+ * Holds if there is a path injection from source to sink
197+ */
198+ deprecated predicate pathInjection ( CustomPathNode source , CustomPathNode sink ) {
199+ pathNotNormalized ( source , sink )
200+ or
201+ pathNotCheckedAfterNormalization ( source , sink )
202+ }
0 commit comments