Flask uses Jinja2 template engine and Flask enables automatic escaping on Jinja2 by default.
If you really want to allow XSS, change {{ task.content }} to {{ task.content|safe }} on your template.
More information: https://flask.palletsprojects.com/en/1.1.x/templating/#controlling-autoescaping
Answer from vremes on Stack Overflowsecurity - Is possible to write XSS vulnerable flask web app? - Stack Overflow
web application - Flask XSS prevention - Information Security Stack Exchange
how does jinja2 prevent XSS attacks? - Stack Overflow
Prevent XSS and SQL Injection in chat system
Videos
I have a chat system im building, relatively simple. Users can sign up and post messages int the chat for others to see (essentially).
The comments are stored in a database and then fetched and put into the html through a jinja loop.
However, theres obviosuly a risk of XSS attacks and I assume SQL injection since the user could input a script tag and it will run.
What is the best way to get round this. I could sanitize the input but then ill will end restricting what the user can type, which i dont want to do.
Hi guys,
I'm learning some Flask, and for that I'm creating a little API (with Flask-RESTful) that will then be consumed by a SPA (Vue.Js) and maybe a mobile app later on.
Now, from what I've read, XSS issues are mainly handled by Jinja2, which will take care of encoding the output and all that stuff. However, given that this is an API and therefore I won't be using templates/Jinja2, the encoding will have to be done in the API views. OWASP suggests Python-Bleach (https://github.com/mozilla/bleach) for this, would you consider this the Python/Flask go-to solution when not using Jinja2?
Any opinions and suggestions are welcomed!
Cheers.