@@ -39,60 +39,35 @@ class DjangoQueryDict extends TaintKind {
3939 }
4040}
4141
42- abstract class DjangoRequestSource extends HttpRequestTaintSource {
43- override string toString ( ) { result = "Django request source" }
44-
45- override predicate isSourceOf ( TaintKind kind ) { kind instanceof DjangoRequest }
46- }
47-
48- /**
49- * Function based views
50- * https://docs.djangoproject.com/en/1.11/topics/http/views/
51- * https://docs.djangoproject.com/en/3.0/topics/http/views/
52- */
53- private class DjangoFunctionBasedViewRequestArgument extends DjangoRequestSource {
54- DjangoFunctionBasedViewRequestArgument ( ) {
55- exists ( DjangoRoute route , FunctionValue view |
56- route .getViewFunction ( ) = view and
57- this = view .getScope ( ) .getArg ( 0 ) .asName ( ) .getAFlowNode ( )
42+ /** A Django request parameter */
43+ class DjangoRequestSource extends HttpRequestTaintSource {
44+ DjangoRequestSource ( ) {
45+ exists ( DjangoRoute route , DjangoViewHandler view , int request_arg_index |
46+ route .getViewHandler ( ) = view and
47+ request_arg_index = view .getRequestArgIndex ( ) and
48+ this = view .getScope ( ) .getArg ( request_arg_index ) .asName ( ) .getAFlowNode ( )
5849 )
5950 }
60- }
6151
62- /**
63- * Class based views
64- * https://docs.djangoproject.com/en/1.11/topics/class-based-views/
65- * https://docs.djangoproject.com/en/3.0/topics/class-based-views/
66- */
67- private class DjangoView extends ClassValue {
68- DjangoView ( ) {
69- Value:: named ( "django.views.generic.View" ) = this .getASuperType ( )
70- or
71- Value:: named ( "django.views.View" ) = this .getASuperType ( )
72- }
73- }
74-
75- private FunctionValue djangoViewHttpMethod ( ) {
76- exists ( DjangoView view | view .lookup ( httpVerbLower ( ) ) = result )
77- }
52+ override string toString ( ) { result = "Django request source" }
7853
79- class DjangoClassBasedViewRequestArgument extends DjangoRequestSource {
80- DjangoClassBasedViewRequestArgument ( ) {
81- this = djangoViewHttpMethod ( ) .getScope ( ) .getArg ( 1 ) .asName ( ) .getAFlowNode ( )
82- }
54+ override predicate isSourceOf ( TaintKind kind ) { kind instanceof DjangoRequest }
8355}
8456
8557/** An argument specified in a url routing table */
8658class DjangoRequestParameter extends HttpRequestTaintSource {
8759 DjangoRequestParameter ( ) {
88- exists ( DjangoRoute route , Function f |
89- f = route .getViewFunction ( ) .getScope ( ) |
60+ exists ( DjangoRoute route , Function f , DjangoViewHandler view , int request_arg_index |
61+ route .getViewHandler ( ) = view and
62+ request_arg_index = view .getRequestArgIndex ( ) and
63+ f = view .getScope ( )
64+ |
9065 this .( ControlFlowNode ) .getNode ( ) = f .getArgByName ( route .getANamedArgument ( ) )
9166 or
9267 exists ( int i | i >= 0 |
9368 i < route .getNumPositionalArguments ( ) and
9469 // +1 because first argument is always the request
95- this .( ControlFlowNode ) .getNode ( ) = f .getArg ( i + 1 )
70+ this .( ControlFlowNode ) .getNode ( ) = f .getArg ( request_arg_index + 1 + i )
9671 )
9772 )
9873 }
0 commit comments