django-security

Configure Django production settings and code against web vulnerabilities.

1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/khetansarvesh/ai_skills_repo --skill django-security-khetansarvesh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-security
Source: https://github.com/khetansarvesh/ai_skills_repo/tree/main/skills/django-security
Command: npx skills add https://github.com/khetansarvesh/ai_skills_repo --skill django-security-khetansarvesh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you prevent common web vulnerabilities in Django applications by turning security best practices into a practical checklist and configuration guide.

Core Features & Use Cases

  • Production Security Settings: Provides secure defaults for DEBUG, cookies, HTTPS enforcement, HSTS, MIME sniffing, clickjacking, and security headers.
  • Authentication & Authorization Hardening: Covers custom user models, stronger password hashing strategies, session configuration, and robust permission/RBAC patterns.
  • Vulnerability Prevention Playbook: Addresses SQL injection prevention with Django ORM patterns, XSS mitigation via template escaping and safe HTML handling, CSRF protection (including AJAX), and secure file upload validation/storage.

Quick Start

Ask the AI: Harden our Django project by reviewing the settings and code for authentication, permissions, CSRF, SQL injection, XSS, file uploads, and security headers, then return a prioritized checklist with exact configuration snippets to apply.

Frequently Asked Questions about django-security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent CSRF attacks in Django forms and AJAX requests?

Preventing CSRF attacks in Django involves enabling CsrfViewMiddleware and rendering the csrf_token template tag in forms. For AJAX, you retrieve the CSRF token from the cookie and include it in a custom X-CSRFToken request header.

What are the best Django production security settings for HTTPS and cookies?

The best Django production security settings for HTTPS and cookies involve setting SECURE_SSL_REDIRECT, SECURE_HSTS_SECONDS, and SESSION_COOKIE_SECURE. You must also disable DEBUG and enforce secure HTTP headers to prevent MIME sniffing and clickjacking.

How does Django prevent SQL injection when using the ORM?

Django prevents SQL injection when using the ORM by automatically parameterizing query inputs. You must avoid raw SQL queries or use parameterized raw() methods, ensuring user input is never directly concatenated into database query strings.

Can I configure Django rate limiting and API authentication for REST apps?

Yes, you can configure Django rate limiting and API authentication for REST apps. The framework supports robust permission and RBAC patterns, allowing you to secure API endpoints by enforcing authentication requirements and throttling request rates.

Why does Django template escaping help with XSS prevention?

Django template escaping helps with XSS prevention by automatically converting sensitive HTML characters to harmless entities. You must avoid marking user-supplied content as safe HTML to ensure malicious scripts are rendered as plain text.

How do I validate and store unsafe file uploads securely in Django?

To validate and store unsafe file uploads securely in Django, you must enforce strict file extension and MIME type validation. You should store uploaded files outside the web root and serve them through a dedicated view to prevent direct execution.