Mark a function as a flask route by adding an AST node tag Example: :: @app.route("/") def index(): return "Hello world" index function in this case should be marked as a flask route
(self, context)
| 27 | self.__propagate_taint(context=context) |
| 28 | |
| 29 | def __mark_flask_route(self, context): |
| 30 | """ |
| 31 | Mark a function as a flask route by adding an AST node tag |
| 32 | Example: |
| 33 | |
| 34 | :: |
| 35 | @app.route("/") |
| 36 | def index(): |
| 37 | return "Hello world" |
| 38 | |
| 39 | |
| 40 | index function in this case should be marked as a flask route |
| 41 | """ |
| 42 | if "flask_route" in context.node.tags: |
| 43 | return |
| 44 | elif "django_view" in context.node.tags: |
| 45 | return |
| 46 | |
| 47 | # Node is a function definition |
| 48 | if not type(context.node) == FunctionDef: |
| 49 | return |
| 50 | # Node has at least one decorator |
| 51 | if not len(context.node.decorator_list) > 0: |
| 52 | return |
| 53 | |
| 54 | # Iterate over decorators |
| 55 | for dec in context.node.decorator_list: |
| 56 | if ( |
| 57 | isinstance(dec, Call) |
| 58 | and dec.full_name == "flask.Flask.route" |
| 59 | ): |
| 60 | log = TaintLog( |
| 61 | path = self.path, |
| 62 | line_no=context.node.line_no, |
| 63 | message="AST node marked as a Flask route" |
| 64 | ) |
| 65 | context.node._taint_log.append(log) |
| 66 | context.node.tags.add("flask_route") |
| 67 | context.visitor.modified = True |
| 68 | return |
| 69 | |
| 70 | def __mark_django_view(self, context): |
| 71 | if "flask_route" in context.node.tags: |