[Flask] Is there a centralized way .. to preprocess URL requests headed to routes.py?

flaskee flaskee at protonmail.com
Fri Jul 3 10:48:13 EDT 2020


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

> On Fri, Jul 3, 2020 at 2:23 AM flaskee via Flask <flask at python.org> wrote:
>
>> routes.py will have possibly many decorators for different pages of a webpage.
>>
>> I'm wondering if there is one central place to inspect *any* request made against a flask site;
>> before it gets to each decorator?
>>
>> The hacking attacks now adays are many and varied --and it would be nice to
>> be able to log or pre-process ALL page requests; to look for SQL attacks, URL injection attacks, etc.
>> Even if the pages being requested are not really on your site; and they are just wildly trying things.
>>
>> Just a way to see/touch EVERYTHING before it hits the decorators.
>>
>> Is there a way to do this?
>>
>> Thanks
>
> Do you mean something like this that runs before every request?
>
> - @app.before_request
>
> - def before_request():
>
> -  app.logger.info("before_request")

Oooooooooooo -- Yes I do!
Thank you!

I just need to get it to show show the actual URL/parms being called.

I'm already here now...

@app.before_request

def before_request():

app.logger.info("before_request_hits log" + request.environ['REMOTE_ADDR'] + ")" )

[10:38:07] {/routes.py:56} INFO - before_request_hits log (8.8.8.8)
[10:38:07] {/routes.py:56} INFO - before_request_hits log (8.8.8.8)
[10:38:07] {/routes.py:56} INFO - before_request_hits log (8.8.8.8)

Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20200703/076e123b/attachment-0001.html>


More information about the Flask mailing list