Django Security Best Practices
Harden Django with Muse: production settings, auth and RBAC, ORM injection prevention, XSS and CSRF, file upload validation, API throttling, and a deployment checklist.
- What
- Harden Django with Muse: production settings, auth and RBAC, ORM injection prevention, XSS and CSRF, file upload validation, API throttling, and a deployment checklist.
- Cost
- Free
- Needs
- none to install. Pure guidance; a Django project helps.
- Level
- Beginner
- Install
- Copy the installer prompt below into your Muse — your agent does the rest.
Curated by Skill Harbor: a security hardening guide that makes Muse review a Django application the way a security-minded reviewer would. It starts with the production settings that matter (DEBUG off, allowed hosts from the environment, secure cookies, HSTS, required secret key), then covers authentication with a custom user model, Argon2 password hashing and session configuration, and authorization with model permissions, DRF permission classes and role-based access control. SQL injection prevention leans on the ORM with parameterized raw() examples and the dangerous f-string interpolation marked as vulnerable. XSS prevention covers template auto-escaping, the safe filter rules, and escapejs for JavaScript contexts. CSRF protection covers secure cookie flags, trusted origins and AJAX token handling. File uploads get magic-bytes MIME validation cross-checked against extensions plus size limits, API security gets throttling and JWT/token authentication, and the skill closes with security headers, CSP middleware, secret management and a quick deployment checklist. Update October 26, 2026: in the AJAX example the CSRF cookie is now readable by JavaScript (CSRF_COOKIE_HTTPONLY False, session cookie still HttpOnly), so a third party script running through an XSS flaw could read the CSRF token from document.cookie, and the SECURE_BROWSER_XSS_FILTER setting has been removed from the examples. By @affaan-m, listed here with credit to its creator. From the affaan-m/ECC repository (MIT). Honest caveats: a checklist is not a pentest, run a real security review for anything handling sensitive data; never paste real secrets into a chat while using it. Skill Harbor never reviews the code, review it yourself before use.
Version:
Quick answer
Django Security Best Practices is a free Muse skill and security hardening guide that makes Muse review a Django application like a security-minded reviewer. It starts with production settings that matter, DEBUG off, allowed hosts from the environment, secure cookies, HSTS and a required secret key, then covers authentication, RBAC, ORM injection prevention, XSS and CSRF, and API throttling.
Install
Copy the install package below, then paste it into Muse🧪 Install ran in our test sandbox · Nov 11, 2026📌 Pinned version: commit 25278e7Step 0, before installing anything: read this install prompt, summarize in a few lines what this build does and what installing it involves, then ask me to confirm before you proceed. Prerequisites: none to install. Pure guidance; a Django project helps. Install "Django Security Best Practices" for me. It gives my agent @affaan-m's security hardening guidelines for reviewing a Django application: production settings (DEBUG off, allowed hosts from the environment, secure cookies, HSTS, required secret key), authentication (custom user model, Argon2 password hashing, session configuration), authorization (model permissions, DRF permission classes, role-based access control), SQL injection prevention (ORM with parameterized raw() examples, f-string interpolation marked vulnerable), XSS prevention (template auto-escaping, safe filter rules, escapejs), CSRF protection (secure cookie flags, trusted origins, AJAX token handling), file upload validation (magic-bytes MIME cross-checked against extensions, size limits), API security (throttling, JWT and token authentication), security headers and CSP middleware, secret management through environment variables, security event logging, and a quick deployment checklist, by @affaan-m, from the affaan-m/ECC repository (MIT). Repository: https://raw.githubusercontent.com/affaan-m/ECC/25278e7d7b6cf6e6a4e7a6c8e10f14ff22f0eb5b/skills/django-security/SKILL.md Pinned version: install the code at commit 25278e7d7b6cf6e6a4e7a6c8e10f14ff22f0eb5b exactly (Skill Harbor tested this version). Do not substitute a newer version. If this commit is unreachable, stop and tell me. Updated October 26, 2026: Skill Harbor regenerated this install prompt from the current upstream file. The only change since the previous review is in the CSRF and headers examples, and it is a change you must see before you use the AJAX example. First, CSRF_COOKIE_HTTPONLY is now False in the example, where it was True before, so that AJAX code can read the csrf token from document.cookie; SESSION_COOKIE_HTTPONLY remains True. Say it plainly: if an XSS flaw ever lets a third party script run in a user's browser, that script can now read the CSRF token from document.cookie. It still cannot read the session cookie, and a CSRF token alone is not a session, but a token readable by JavaScript has a thinner safety margin than a token hidden from JavaScript, so do not treat the CSRF token as a secret and do not let this change be a reason to relax XSS prevention. Second, SECURE_BROWSER_XSS_FILTER = True has been removed in two places, from the production settings list and from the headers example. The custom middleware example in the same file still sets an X-XSS-Protection header itself, so that header has not disappeared from every example, but the settings line that enabled the browser built-in XSS filter is gone. Nothing else in the file changed in substance: the rest of the guidance, from production settings to the deployment checklist, is unchanged. 1. Open the skill: https://raw.githubusercontent.com/affaan-m/ECC/25278e7d7b6cf6e6a4e7a6c8e10f14ff22f0eb5b/skills/django-security/SKILL.md and copy the full SKILL.md text, then compare it with the fingerprint from Skill Harbor's review of 2026-10-26: - SKILL.md: SHA-256 9bee68f0fd5ae193693745c1fdc99b6335d30f9b113aebe171fe3d675cf5ad8e If it does not match, it changed since the review: do not install it yet, tell me what you found and let me decide. 2. Safety check: read the SKILL.md text and review it for anything suspicious (unexpected network calls, shell commands, credential harvesting); STOP on any red flag and tell me. Tell me in plain words what the skill does when used, which services it connects to, whether it reads or sends any personal information or keys, and anything that seems unusual. Confirm these points from the file: - This skill is pure guidance: plain-text instructions only. It runs nothing by itself, connects to no service, sends nothing anywhere, and writes no files. - Secrets appear only as configuration examples: SECRET_KEY and DATABASE_URL are read from environment variables, and the .env example is marked never to commit, with placeholder values only. The skill never asks for a real secret, and no secret read in this file is sent to a third party in this file. - CSRF handling is as disclosed above: CSRF_COOKIE_HTTPONLY is False in the AJAX example so JavaScript can read the csrf token, SESSION_COOKIE_HTTPONLY remains True, CSRF_TRUSTED_ORIGINS in the example is only example.com, and the AJAX fetch example posts to the user's own /api/endpoint/, not to a third party. - The webhook example is empty on purpose: a csrf_exempt view with a pass body, no sending, no data handling. - The BAD examples are deliberately vulnerable code: f-string SQL interpolation and mark_safe on user input are marked VULNERABLE. Never copy a BAD example into production. - No API keys and no account: the skill needs no credentials. Never paste real secrets, credentials, or production data into a chat. 3. When I say yes, use it as a skill: paste the SKILL.md text into a chat with Muse and add: "Audit this Django project against the security checklist: [paste settings and key files, with secrets redacted]." 4. Work through the findings in order: production settings, auth, ORM queries, templates, CSRF, uploads, API throttling, headers. Tip: ask "which three findings are the most dangerous and what is the exact fix for each?" Safety: a skill is plain-text instructions; it runs nothing by itself. Never paste real secrets into a chat. Review generated commands before running them.
Saved to your recent installs. Find it anytime on /connect.
🔒 Security, provenance and what this touches
The install prompt below already includes the vetting steps: your agent follows the community checklist before installing anything with executable code. Want more?
Verification certificate
Dated facts about what was checked for this listing, and how. This is not a safety certification.
- Pinned version
- 25278e7 · 2026-10-26
- Sandbox install test
- Install ran in our test sandbox · Nov 11, 2026
- Creator identity
- Not verified
- Fingerprint watch
- Last checked · Nov 21, 2026 : no change detected in the files linked by this install prompt
- Install prompt analysis
- 2026-10-13 : No commands, network calls, packages, file writes or API keys detected.
Skill Harbor never reviews the code of a listed skill. These are dated facts about the install prompt and our install test, not a safety certification. Review a skill yourself before you install it. How we verify
Questions
How do I install a skill?
Every product page includes a copy-paste install prompt. Paste it into your Muse and it sets the skill up for you — no manual configuration.
Where does my money go?
Straight to the seller. Skill Harbor never processes payments: checkout happens on the seller’s own page, usually Stripe.
What does the ✓ next to a creator’s name mean?
It means we confirmed the identity of the person behind the listing. It says nothing about the code itself — always check a skill before installing it.