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
1515private import semmle.python.frameworks.internal.PoorMansFunctionResolution
1616private import semmle.python.frameworks.internal.SelfRefMixin
1717private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
18+ private import semmle.python.security.dataflow.UrlRedirectCustomizations
1819
1920/**
2021 * INTERNAL: Do not use.
@@ -2788,4 +2789,31 @@ module PrivateDjango {
27882789
27892790 override predicate csrfEnabled ( ) { decoratorName in [ "csrf_protect" , "requires_csrf_token" ] }
27902791 }
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+ }
27912819}
Original file line number Diff line number Diff line change @@ -70,31 +70,4 @@ module UrlRedirect {
7070 * A comparison with a constant string, considered as a sanitizer-guard.
7171 */
7272 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- }
10073}
You can’t perform that action at this time.
0 commit comments