Recall & Review
beginner
What does CSRF stand for and why is it a security risk?
CSRF stands for Cross-Site Request Forgery. It is a security risk because it tricks a user’s browser into making unwanted actions on a website where they are authenticated, without their consent.
Click to reveal answer
beginner
How does Django protect against CSRF attacks by default?
Django uses a CSRF token, a unique secret value, that must be included in POST forms and AJAX requests. The server checks this token to confirm the request is from the trusted user.
Click to reveal answer
beginner
Where should you include the CSRF token in a Django HTML form?
Inside the form tag, you include {% csrf_token %} template tag. This adds a hidden input with the CSRF token value that the server will verify on form submission.
Click to reveal answer
intermediate
What happens if a POST request in Django does not include a valid CSRF token?
Django will reject the request and return a 403 Forbidden error. This prevents unauthorized or forged requests from being processed.
Click to reveal answer
intermediate
How can you exempt a Django view from CSRF protection if needed?
You can use the @csrf_exempt decorator on the view function to disable CSRF checks for that view. Use this carefully as it removes protection.
Click to reveal answer
What is the main purpose of the CSRF token in Django?
✗ Incorrect
The CSRF token ensures that the request is made intentionally by the authenticated user, protecting against forged requests.
Where do you add the CSRF token in a Django template form?
✗ Incorrect
The {% csrf_token %} tag adds a hidden input with the token inside the form, which Django checks on submission.
What HTTP status code does Django return if CSRF validation fails?
✗ Incorrect
Django returns 403 Forbidden to block requests that fail CSRF validation.
Which Django decorator disables CSRF protection for a view?
✗ Incorrect
The @csrf_exempt decorator disables CSRF checks for the decorated view.
CSRF attacks exploit which of the following?
✗ Incorrect
CSRF attacks use the user’s authenticated session to perform unwanted actions without their knowledge.
Explain how Django’s CSRF protection works in a typical form submission.
Think about what happens from form rendering to form submission.
You got /4 concepts.
Describe a situation where you might need to disable CSRF protection in Django and how to do it safely.
Consider when CSRF tokens are not practical but security is still important.
You got /4 concepts.