Bird
0
0

Given this code snippet: user_input = "1; DROP TABLE users;" User.objects.filter(id=user_input) What happens when this runs?

medium📝 Predict Output Q5 of 15
Django - Security Best Practices
Given this code snippet: user_input = "1; DROP TABLE users;" User.objects.filter(id=user_input) What happens when this runs?
AThe users table is dropped from the database
BA syntax error is raised
CThe ORM safely treats input as a parameter, no table is dropped
DThe query returns all users
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter handling in filter()

    Input is passed as a parameter, not executed as SQL.
  2. Step 2: Assess risk of injection

    SQL injection does not occur; dangerous input is treated as a string.
  3. Final Answer:

    The ORM safely treats input as a parameter, no table is dropped -> Option C
  4. Quick Check:

    Parameter safety = No injection [OK]
Quick Trick: Dangerous input is safe with ORM filters [OK]
Common Mistakes:
MISTAKES
  • Believing input runs as SQL commands
  • Expecting errors from semicolons in input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes