Challenge - 5 Problems
SQL Injection Defender
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
How does Django ORM protect against SQL injection?
Which of the following best explains how Django ORM prevents SQL injection attacks?
Attempts:
2 left
💡 Hint
Think about how query parameters are handled inside the ORM.
✗ Incorrect
Django ORM uses parameterized queries which safely separate data from code, preventing injection.
❓ component_behavior
intermediate1:30remaining
Output of a Django ORM filter with user input
Given the code below, what will be the output if
user_input = "1 OR 1=1"?Django
user_input = "1 OR 1=1" results = MyModel.objects.filter(id=user_input) print(results.query)
Attempts:
2 left
💡 Hint
Look at how Django ORM treats filter parameters as values, not code.
✗ Incorrect
Django ORM treats the filter value as a literal string, escaping it properly, so the query is safe.
📝 Syntax
advanced2:00remaining
Identify the unsafe raw SQL usage in Django
Which option shows unsafe raw SQL usage vulnerable to SQL injection?
Attempts:
2 left
💡 Hint
Look for string formatting inside raw SQL queries.
✗ Incorrect
Option C directly inserts user input into the SQL string, allowing injection.
🔧 Debug
advanced2:00remaining
Why does this Django raw query cause SQL injection?
Consider this code snippet:
query = "SELECT * FROM myapp_mymodel WHERE username = '%s'" % user_input results = MyModel.objects.raw(query)What is the main problem here?
Attempts:
2 left
💡 Hint
Think about how string formatting works with user input.
✗ Incorrect
Using string formatting inserts user input directly, allowing malicious SQL code to run.
❓ state_output
expert2:30remaining
Result count after filtering with unsafe input in Django ORM
Given the model
Product with integer field id, and this code:
user_input = "1 OR 1=1" qs = Product.objects.filter(id=user_input) count = qs.count()What is the value of
count if the database has 5 products with ids 1 to 5?Attempts:
2 left
💡 Hint
Consider how Django ORM treats filter values and the field type.
✗ Incorrect
Django ORM treats the input as a string and tries to match it exactly. Since '1 OR 1=1' is not a valid integer, no rows match.