Skip to content

Conversation

tausbn
Copy link
Contributor

@tausbn tausbn commented Aug 25, 2025

The flask.request global object is commonly used in request handlers to access data in the active request. In our modelling, we handled this by treating the initial (module-local) definition of request as a source of remote flow. In practice this meant a lot of alerts would act as if from flask import request was the ultimate "source" of remote flow, and to find the actual request-handler-local instance of request one would have to inspect the data-flow path between source and sink.

To improve this state of affairs, I have made the following changes to the definition of FlaskRequestSource:

  • We no longer consider from flask import request to be a source.
  • Instead, we look at all places where that request value can flow, and include only the ones that are LocalSourceNodes (so that inside a request handler, the first occurrence of the request object is the source).

In practice, this leads to alerts that are much easier to decipher.

The `flask.request` global object is commonly used in request handlers
to access data in the active request. In our modelling, we handled this
by treating the initial (module-local) definition of `request` as a
source of remote flow. In practice this meant a lot of alerts would act
as if `from flask import request` was the ultimate "source" of remote
flow, and to find the actual request-handler-local instance of `request`
one would have to inspect the data-flow path between source and sink.

To improve this state of affairs, I have made the following changes to
the definition of `FlaskRequestSource`:

- We no longer consider `from flask import request` to be a source.
- Instead, we look at all places where that `request` value can flow,
and include only the ones that are `LocalSourceNode`s (so that inside a
request handler, the first occurrence of the `request` object is the
source).

In practice, this leads to alerts that are much easier to decipher.
tausbn added 2 commits August 28, 2025 13:23
As it turns out, referring to the request object using `flask.request`
is not uncommon, and this meant restricting to `Name` nodes was too
strong. With the changes in this commit, we now include those
occurrences as well.
Really starting to regret our widespread use of `flask.request` as _the_
example of a remote flow source.
@tausbn tausbn force-pushed the tausbn/python-refine-location-of-flask-request-sources branch from a842023 to 0f4f909 Compare August 29, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant