Skip to content

Python: FlaskApp instances do not reliably track subclasses #21854

@UpsideDownFoxxo

Description

@UpsideDownFoxxo

I was running a set of queries on the CTFd repository, and got suspiciously few results for endpoints. After some experimenting I found out that they subclass Flask, which the current query for FlaskApp::instance() does not seem to track.

Minimal example:

Query:

import python

import semmle.python.frameworks.Flask
import semmle.python.ApiGraphs


from API::Node node
where Flask::FlaskApp::instance() = node
select node

Python:

from flask import Flask


class Sub(Flask):
    def __init__(self, *args, **kwargs):
        Flask.__init__(self, *args, **kwargs)


app = Sub(__name__)


@app.route("/")
def hello():
    return "world"

CodeQL is not able to identify Sub as a Flask app, which means the route setup for hello cannot be detected as well.

Adding .getASubclass*() to FlaskApp::instance() would probably fix this. If this can be overridden without changes to the library I am open to suggestions, my knowledge of the QL modules is not that great as of now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PythonquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions