Flask interview question · Most asked
How do you prevent SQL injection in Flask apps?
Summary
Use SQLAlchemy's query building or bound parameters (text('... WHERE id = :id') with params) and never build SQL with f-strings from user input; allow-list identifiers like sort columns.
Longer Answer
ORMs parameterize values automatically, but raw text() with string interpolation reintroduces risk. Validate and map user-chosen sort fields to known columns.
Key Points
- ORM / bound parameters
- No f-string SQL
- Allow-list identifiers
More most-asked Flask questions
- How do you access request data and build responses in Flask?
- How do Flask sessions work and what are their security implications?
- What is the application factory pattern in Flask and why use it?
- What is Flask and what does 'microframework' mean?
- Explain Flask's application context and request context.
- What are Blueprints in Flask?
- How does routing work in Flask, including variable rules and HTTP methods?
- How do you use SQLAlchemy with Flask (Flask-SQLAlchemy 3.x)?