Loading...
Loading...
Guideline for designing, implementing, and verifying secure Python applications following OWASP Top 10 best practices. Use when the user wants to: (1) review Python code for security vulnerabilities, (2) design a secure Python application architecture, (3) implement security features (authentication, authorization, cryptography, input validation), (4) audit Python dependencies for known vulnerabilities, (5) create security checklists or verification plans, (6) fix security bugs or harden existing Python code, (7) set up security testing and static analysis (bandit, safety, semgrep), or (8) handle any Python security concern including injection prevention, secure deserialization, SSRF protection, secrets management, and secure deployment.
npx skill4agent add jim60105/copilot-prompt python-security| Never | Instead |
|---|---|
| |
| |
| |
| |
| |
| String formatting / f-strings in SQL | Parameterized queries ( |
| |
| MD5 / SHA1 for password hashing | |
| |
Bare | |
| Hardcoded secrets in source code | Environment variables or secret manager (Vault, AWS SM) |
| Environment-specific configuration |
banditsemgreppylintpip-auditsafetydetect-secrets# Bandit — static analysis
bandit -r src/ -f json -o bandit-report.json
# pip-audit — dependency vulnerabilities
pip-audit
# Safety — alternative dependency check
safety check
# detect-secrets — secrets scanning
detect-secrets scan > .secrets.baseline
# Semgrep — advanced pattern matching
semgrep --config=p/python --config=p/owasp-top-ten src/requirements.txtpip install --require-hashes -r requirements.txtpip-audittrivyStrict-Transport-SecurityContent-Security-PolicyX-Content-Type-Options: nosniffX-Frame-Options: DENY| # | Category | Python-Specific Risks | Primary Mitigation |
|---|---|---|---|
| A01 | Broken Access Control | Missing | Centralized auth middleware, object-level permissions, |
| A02 | Security Misconfiguration | | Environment-specific config, explicit CORS origins, disable docs in prod, |
| A03 | Software Supply Chain Failures | Unpinned deps, typosquatting, no SBOM, unvetted transitive deps, CI/CD secrets exposure | |
| A04 | Cryptographic Failures | | |
| A05 | Injection | SQL via f-strings/ | safe |
| A06 | Insecure Design | No rate limiting, missing input validation layer, no abuse case modeling | Threat modeling, validation at boundaries (Pydantic), rate limiting middleware |
| A07 | Authentication Failures | Weak session config, JWT | Secure session settings, explicit |
| A08 | Software or Data Integrity Failures | | |
| A09 | Security Logging and Alerting Failures | Logging passwords/tokens, no auth event logging, missing alerting, no playbooks | Structured logging with field filtering, audit trail, alerting thresholds, honeytokens |
| A10 | Mishandling of Exceptional Conditions | Bare | Specific exception types, context managers, centralized error handlers, fail-closed patterns |
pip-auditsafety checkbandit -r src/semgrep# === Static Analysis ===
pip install bandit && bandit -r src/ -f json -o bandit-report.json
pip install semgrep && semgrep --config=p/python --config=p/owasp-top-ten src/
# === Dependency Audit ===
pip install pip-audit && pip-audit
pip install safety && safety check
# === Secrets Detection ===
pip install detect-secrets && detect-secrets scan > .secrets.baseline
# === Pin Dependencies with Hashes ===
pip install pip-tools && pip-compile --generate-hashes requirements.in
# === Container Scanning ===
# trivy image <image-name>