django-security

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Django applications face common web vulnerabilities like SQL injection, XSS, CSRF attacks, and misconfigured production settings. This Skill provides concrete code patterns and checklists to secure Django projects against these threats. ## Core Features & Use Cases - Production Hardening: Configures security headers, HTTPS redirects, HSTS, secure cookies, and environment-based secret management. - Authentication & Authorization: Implements custom user models, Argon2 password hashing, RBAC, and DRF permission classes. - Attack Prevention: Provides safe patterns for ORM queries, template escaping, CSRF tokens, file upload validation, and API rate limiting. - Use Case: When deploying a Django app to production, use this Skill to audit settings, enforce secure defaults, and add throttling to REST API endpoints. ## Quick Start Ask the AI to review your Django settings and views for security issues using the django-security guidelines.

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 SQL strings with f-strings or concatenation.

How to configure Django security settings for production?

Set DEBUG to False, enable SECURE_SSL_REDIRECT, SECURE_HSTS_SECONDS, secure session and CSRF cookies, and load SECRET_KEY from environment variables. Also configure ALLOWED_HOSTS and strong password validators.

Does Django protect against XSS attacks by default?

Yes, Django templates auto-escape variables by default. Avoid using the safe filter or mark_safe on untrusted user input, and use escapejs for values inserted into JavaScript contexts.

How do I add rate limiting to Django REST Framework APIs?

Configure DEFAULT_THROTTLE_CLASSES with AnonRateThrottle and UserRateThrottle in REST_FRAMEWORK settings, then define rates like 100/day for anonymous users. Custom throttle classes allow scopes such as burst or sustained limits.

Why is CSRF protection failing for my Django AJAX requests?

AJAX POST requests must include the X-CSRFToken header read from the csrftoken cookie. Ensure CSRF middleware is enabled and the domain is listed in CSRF_TRUSTED_ORIGINS for cross-origin requests.