django-security

Enforce authentication, authorization, and secure Django settings.

1.8k|303|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/xu-xiang/everything-claude-code-zh --skill django-security-xu-xiang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-security
Source: https://github.com/xu-xiang/everything-claude-code-zh/tree/main/skills/django-security
Command: npx skills add https://github.com/xu-xiang/everything-claude-code-zh --skill django-security-xu-xiang

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

本 Skill 提供面向 Django 应用的安全最佳实践,覆盖身份认证、授权、CSRF、XSS、SQL 注入防护以及安全部署配置,帮助开发团队降低安全风险。

Core Features & Use Cases

  • Authentication hardening: 强化用户认证(如自定义用户模型、强密码策略、账户锁定等)。
  • Authorization & permissions: 采用最小权限、RBAC/自定义权限模型,确保数据访问控制。
  • CSRF/XSS 防护与安全头部: 启用 CSRF、输出转义、设置严格的安全头部(CSP、X-Frame-Options 等)。
  • SQL 注入防护: 使用 Django ORM/参数化查询,避免 SQL 拼接。
  • Secure deployment: 生产环境安全设置(DEBUG=False、ALLOWED_HOSTS、安全密钥管理、会话/Cookie 策略)。

Quick Start

在你的 Django 项目中应用上述最佳实践,启用生产就绪的安全配置。

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 applications?

Prevent SQL injection in Django by using the built-in ORM and parameterized queries instead of raw SQL string concatenation. This ensures user input is automatically escaped by the framework's query sets.

How do I configure Django for production-ready security?

Configure Django production security by setting DEBUG=False, defining ALLOWED_HOSTS, enforcing secure key management, and applying strict session and cookie policies. Update your settings.py and middleware to enforce these defaults.

What's the best way to implement authentication and authorization in Django?

Implement Django authentication and authorization by using custom user models, enforcing strong password policies, and applying RBAC or custom permission models. Adopt a least privilege approach for strict data access control.

How do I enable CSRF and XSS protection in Django?

Enable Django CSRF and XSS protection by activating CSRF middleware, leveraging automatic template output escaping, and setting strict security headers like CSP and X-Frame-Options to prevent web vulnerabilities.

Do I need additional dependencies to secure Django session management?

No additional dependencies are required. Secure Django session management and security hardening are achieved by updating standard Django settings and middleware configurations natively supported by the framework.