File tree Expand file tree Collapse file tree 2 files changed +28
-27
lines changed
python/ql/lib/semmle/python Expand file tree Collapse file tree 2 files changed +28
-27
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ private import semmle.python.regex
15
15
private import semmle.python.frameworks.internal.PoorMansFunctionResolution
16
16
private import semmle.python.frameworks.internal.SelfRefMixin
17
17
private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
18
+ private import semmle.python.security.dataflow.UrlRedirectCustomizations
18
19
19
20
/**
20
21
* INTERNAL: Do not use.
@@ -2788,4 +2789,31 @@ module PrivateDjango {
2788
2789
2789
2790
override predicate csrfEnabled ( ) { decoratorName in [ "csrf_protect" , "requires_csrf_token" ] }
2790
2791
}
2792
+
2793
+ private predicate djangoUrlHasAllowedHostAndScheme (
2794
+ DataFlow:: GuardNode g , ControlFlowNode node , boolean branch
2795
+ ) {
2796
+ exists ( API:: CallNode call |
2797
+ call =
2798
+ API:: moduleImport ( "django" )
2799
+ .getMember ( "utils" )
2800
+ .getMember ( "http" )
2801
+ .getMember ( "url_has_allowed_host_and_scheme" )
2802
+ .getACall ( ) and
2803
+ g = call .asCfgNode ( ) and
2804
+ node = call .getParameter ( 0 , "url" ) .asSink ( ) .asCfgNode ( ) and
2805
+ branch = true
2806
+ )
2807
+ }
2808
+
2809
+ /**
2810
+ * A call to `django.utils.http.url_has_allowed_host_and_scheme`, considered as a sanitizer-guard for URL redirection.
2811
+ *
2812
+ * See https://docs.djangoproject.com/en/4.2/_modules/django/utils/http/
2813
+ */
2814
+ private class DjangoAllowedUrl extends UrlRedirect:: Sanitizer {
2815
+ DjangoAllowedUrl ( ) {
2816
+ this = DataFlow:: BarrierGuard< djangoUrlHasAllowedHostAndScheme / 3 > :: getABarrierNode ( )
2817
+ }
2818
+ }
2791
2819
}
Original file line number Diff line number Diff line change @@ -70,31 +70,4 @@ module UrlRedirect {
70
70
* A comparison with a constant string, considered as a sanitizer-guard.
71
71
*/
72
72
class StringConstCompareAsSanitizerGuard extends Sanitizer , StringConstCompareBarrier { }
73
-
74
- private import semmle.python.ApiGraphs
75
-
76
- private predicate djangoUrlHasAllowedHostAndScheme (
77
- DataFlow:: GuardNode g , ControlFlowNode node , boolean branch
78
- ) {
79
- exists ( API:: CallNode call |
80
- call =
81
- API:: moduleImport ( "django" )
82
- .getMember ( "utils" )
83
- .getMember ( "http" )
84
- .getMember ( "url_has_allowed_host_and_scheme" )
85
- .getACall ( ) and
86
- g = call .asCfgNode ( ) and
87
- node = call .getParameter ( 0 , "url" ) .asSink ( ) .asCfgNode ( ) and
88
- branch = true
89
- )
90
- }
91
-
92
- /**
93
- * A call to `django.utils.http.url_has_allowed_host_and_scheme`, considered as a sanitizer-guard.
94
- */
95
- private class DjangoAllowedUrl extends Sanitizer {
96
- DjangoAllowedUrl ( ) {
97
- this = DataFlow:: BarrierGuard< djangoUrlHasAllowedHostAndScheme / 3 > :: getABarrierNode ( )
98
- }
99
- }
100
73
}
You can’t perform that action at this time.
0 commit comments