» pip install Flask-Security
Flask security best practices
How to secure a flask app
Why is WSGI important?
Before WSGI, Python web frameworks and servers often had specific coupling, meaning a particular web framework could only run on certain web servers. WSGI broke this limitation, enabling more flexibility and interoperability.
What is Web Server Gateway Interface (WSGI) standard?
WSGI allows for a standardized way for web servers to communicate with web applications written in Python. It's an intermediary layer that enables web servers to forward requests to a web application or framework and then deliver responses back to a client.
How does WSGI compare to similar concepts in other languages?
WSGI is similar in purpose to the Java Servlet API in Java or Rack in Ruby. These technologies abstract the details of HTTP requests and responses, allowing developers to focus on writing web application logic rather than dealing with underlying server communication.
I would like to secure my Flask app, however as I'm new to this I would like what are the main things that one should look for in order to secure it, especially from XSS.
I was told to be careful when using forms and better use FlaskWTF for all the forms in my website, but is it enough ?
If you have any course or ressource that could help I would be very grateful <3
» pip install Flask-Security-Too
Flask-Security is now deprecated, so I wouldn't recommend using it in production. There is a fork of it called Flask Security Too but it doesn't seem very widely followed.
To be honest even when it was maintained it wasn't my favourite as I think it tried to do too much.
Flask-Login on the other hand is a solid library. It is very "flasky" in the sense that it is low level and deals with the really annoying stuff (creating a session, persisting it with cookies, delivering a current_user, putting certain routes behind a login_required decorator) and then letting you design your own flow and pull in the libraries you want.
For instance if you want social login or OAuth token storage then Flask-Dance, which integrates nicely with Flask-Login and is actively maintained, smashes Flask-Social which integrates with Flask-Security.
There is also Flask-User, which gets good reviews but last commit was in 2019, which is a little scary.
Flask-Security-Too, while it can be complex if you try to use all of its features, proves to actually be pretty easy to set up production-ready applications. It is actively maintained. I have a few working projects in production using this library (v4.x.x). Not too long ago, there has been a v5.x.x release as well.
You should definitely check that out.
- Flask-Security-Too: https://flask-security-too.readthedocs.io/
- My Example Application: https://github.com/hrishikeshrt/flask-bootstrap-anywhere