Django

Django Security

CSRF protection, XSS prevention, SQL injection, clickjacking, HTTPS, security middleware, best practices

22 pertanyaan wawancara·
Mid-Level
1

What is the main purpose of the CSRF token in Django?

Jawaban

The CSRF token protects against Cross-Site Request Forgery attacks where a malicious site sends requests on behalf of an authenticated user. Django generates a unique token per session and verifies its presence in POST forms. This prevents attackers from forging requests since they cannot guess the random token.

2

How to include the CSRF token in a Django form?

Jawaban

The csrf_token template tag automatically generates a hidden field containing the CSRF token. It must be placed inside the form tag for POST requests. Django then verifies this token via the CsrfViewMiddleware. Without this tag, the form will be rejected with a 403 Forbidden error.

3

Which decorator allows exempting a view from CSRF verification?

Jawaban

The csrf_exempt decorator disables CSRF protection for a specific view. It is useful for external API endpoints that cannot provide a CSRF token. However, its use should be limited as it exposes the view to CSRF attacks. For APIs, token-based authentication is preferred.

4

How does Django automatically protect against XSS attacks in templates?

5

Which template filter allows displaying unescaped HTML content in Django?

+19 pertanyaan wawancara

Kuasai Django untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis