Bird
0
0

What will be the output of this Django ORM query if user_input = "Robert'); DROP TABLE users;--"?

medium📝 Predict Output Q13 of 15
Django - Security Best Practices
What will be the output of this Django ORM query if user_input = "Robert'); DROP TABLE users;--"?
users = User.objects.filter(username=user_input)
print(users.query)
AA raw SQL query that deletes the users table
BAn empty query with no filtering
CA syntax error due to unescaped quotes
DA safe SQL query with escaped input preventing injection
Step-by-Step Solution
Solution:
  1. Step 1: Understand ORM query with dangerous input

    ORM escapes dangerous characters in user_input to prevent SQL injection.
  2. Step 2: Analyze printed query behavior

    Printed query shows safe SQL with escaped input, not raw injection or errors.
  3. Final Answer:

    A safe SQL query with escaped input preventing injection -> Option D
  4. Quick Check:

    ORM escapes dangerous input = B [OK]
Quick Trick: ORM escapes dangerous input, so injection won't happen [OK]
Common Mistakes:
MISTAKES
  • Assuming raw SQL runs as is
  • Expecting syntax errors from quotes
  • Thinking ORM ignores dangerous input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes