Back to Home
Secure SQL Lab
This lab demonstrates secure SQL practices using prepared statements. Try entering any text, including potential attack payloads, and see how the code safely handles them.
Search Users
Secure Code:
# Python (Flask)
query = "SELECT * FROM users WHERE username = ?"
result = db.execute(query, (user_input,))Results
Enter a search query and click Search to see results
Test with these payloads:
Why is this secure?
- Parameterized Queries: The SQL structure is defined separately from the data, preventing injection.
- Type Safety: Parameters are treated as data values, never as executable code.
- Database Driver Protection: The database driver handles proper escaping and validation.
Best Practices Summary
- Always use prepared statements or parameterized queries
- Never concatenate user input into SQL strings
- Validate and sanitize all user input
- Use least privilege database accounts
- Implement proper error handling
- Keep database software updated