django-security

Implements Django security practices for authentication, authorization, CSRF, XSS, and SQL injection prevention.

Updated Jun 13, 2026
One-click install
npx skills add https://github.com/malinovskiy-makar/qls --skill django-security-malinovskiy-makar
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-security
Source: https://github.com/malinovskiy-makar/qls/tree/main/.claude/skills/django-security
Command: npx skills add https://github.com/malinovskiy-makar/qls --skill django-security-malinovskiy-makar

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Django applications face common vulnerabilities like SQL injection, XSS, CSRF attacks, and misconfigured production settings. This Skill provides concrete code patterns and checklists to secure authentication, authorization, file uploads, APIs, and deployment configurations. ## Core Features & Use Cases - Production Hardening: Configure DEBUG, ALLOWED_HOSTS, HSTS, secure cookies, and environment-based secrets for safe deployments. - Authentication & Authorization: Set up custom user models, Argon2 password hashing, RBAC, and DRF permission classes like IsOwnerOrReadOnly. - Attack Prevention: Apply ORM-safe queries, template auto-escaping, CSRF tokens, CSP headers, rate limiting, and file upload validation with magic-byte checks. - Use Case: When reviewing a Django app before launch, use this Skill to audit settings, add throttling to API endpoints, and validate uploaded files against allowed MIME types. ## Quick Start Review my Django project's settings and views for security issues and apply the recommended fixes.

Frequently Asked Questions about django-security

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

FAQPage Schema
How do I prevent SQL injection in Django?

Use the Django ORM, which automatically escapes query parameters, or pass parameters to raw() queries as a list. Never interpolate user input directly into raw SQL strings with f-strings or concatenation.

How do I set up role-based access control in Django?

Add a role field to a custom user model with choices like admin, moderator, and user, then enforce access with mixins that raise PermissionDenied in dispatch(). You can also combine Django groups and custom model permissions for finer control.

What security settings should Django use in production?

Set DEBUG to False, configure ALLOWED_HOSTS, enable SECURE_SSL_REDIRECT, HSTS, secure and HttpOnly cookies, and X_FRAME_OPTIONS. Load SECRET_KEY from environment variables and raise an error if it is missing.

How do I validate file uploads in Django?

Check the file's magic bytes with python-magic or the filetype package against an allowed MIME list, cross-check the extension, and enforce a size limit in model validators. Serve uploads from a separate domain or storage like S3.

Does Django protect against XSS by default?

Yes, Django templates auto-escape variables by default. Avoid using the safe filter or mark_safe on user input; use escape() or format_html instead, and add CSP and X-XSS-Protection headers for defense in depth.

How do I add rate limiting to a Django REST API?

Configure DRF throttling with AnonRateThrottle and UserRateThrottle in DEFAULT_THROTTLE_CLASSES and set rates like 100/day for anonymous users. Create custom throttle classes with scoped rates for burst or sustained limits.