Python Security Scan Skill
This skill enables comprehensive security scanning of Python projects based on OWASP guidelines, Python security best practices, and framework-specific vulnerabilities.
When to Use This Skill
- Security audits of Python applications
- Code review for security vulnerabilities
- Pre-deployment security checks
- Dependency vulnerability assessment
- Detecting hardcoded secrets and credentials
- Framework-specific security reviews (Flask, Django, FastAPI)
Supported Frameworks
This skill automatically detects and applies framework-specific checks for:
- Flask - Template injection, session security, CORS, extensions
- Django - ORM injection, CSRF, template security, settings
- FastAPI - Dependency injection, Pydantic validation, OAuth2
- General Python - Core language vulnerabilities applicable to all projects
Scan Types
1. Quick Scan
Fast scan focusing on critical vulnerabilities:
- Hardcoded secrets, API keys, and credentials
- Dangerous function usage (
eval, exec, pickle.loads)
- Command injection via
subprocess, os.system
- SQL injection patterns
- Known vulnerable dependencies
2. Full Scan
Comprehensive security assessment covering:
- All OWASP Top 10:2025 categories
- Python-specific vulnerabilities
- Framework-specific security issues
- Injection vulnerabilities (SQL, NoSQL, Command, LDAP)
- Insecure deserialization
- Authentication and authorization flaws
- Cryptographic failures
- Security misconfigurations
- Dependency audit (CVE check)
- Environment variable and secrets exposure
3. Targeted Scan
Focus on specific vulnerability categories:
--injection - SQL/NoSQL/Command/LDAP injection
--deserialization - Pickle, YAML, JSON deserialization
--auth - Authentication/authorization issues
--secrets - Hardcoded credentials
--deps - Dependency vulnerabilities
--crypto - Cryptographic issues
--flask - Flask-specific vulnerabilities
--django - Django-specific vulnerabilities
--fastapi - FastAPI-specific vulnerabilities
Scan Procedure
Step 1: Project Discovery
- Identify project type and framework:
- Check for
requirements.txt, Pipfile, pyproject.toml, setup.py
- Detect Flask (
from flask import), Django (django.conf), FastAPI (from fastapi import)
- Locate configuration files
- Map the codebase structure
Step 2: Framework Detection
# Detection patterns
Flask: "from flask import", "Flask(__name__)"
Django: "django.conf.settings", "INSTALLED_APPS", "manage.py"
FastAPI: "from fastapi import", "FastAPI()"
Step 3: Dependency Audit
Run the dependency audit script:
./scripts/dependency-audit.sh /path/to/project
Or manually:
pip-audit
# or
safety check
Step 4: Secret Scanning
Scan for hardcoded secrets:
python scripts/secret-scanner.py /path/to/project
Important: Environment File Handling
- By default, real
.env files are SKIPPED (.env, .env.local, .env.production, etc.)
- These files contain actual secrets and should not be in version control
- Only
.env.example and .env.template files are analyzed for documentation quality
- Use
--include-env-files flag only if explicitly requested by user
The scanner will:
- Scan source code for hardcoded secrets
- Analyze
.env.example templates to check:
- Which sensitive variables are documented
- Whether variables have descriptions (comments)
- If placeholder values look like real secrets
- Suggestions for missing common variables (SECRET_KEY, DATABASE_URL, etc.)
Step 5: Pattern Analysis
For each file in the codebase, check against patterns in:
references/python-vulnerabilities.md - Core Python issues
references/injection-patterns.md - Injection flaws
references/deserialization.md - Insecure deserialization
references/flask-security.md - Flask vulnerabilities
references/django-security.md - Django vulnerabilities
references/fastapi-security.md - FastAPI vulnerabilities
Step 6: Report Generation
Generate a security report using:
assets/report-template.md - Report structure
Severity Classification
| Severity |
Description |
Action Required |
| CRITICAL |
Exploitable vulnerability with severe impact |
Immediate fix required |
| HIGH |
Significant security risk |
Fix before deployment |
| MEDIUM |
Potential security issue |
Fix in next release |
| LOW |
Minor security concern |
Consider fixing |
| INFO |
Security best practice suggestion |
Optional improvement |
Key Files to Scan
Always Check
**/*.py - All Python source files
requirements.txt, Pipfile, pyproject.toml - Dependencies
setup.py, setup.cfg - Package configuration
config.py, settings.py - Configuration files
**/secrets*, **/credentials* - Obvious secret locations
Environment Files
.env.example, .env.template - SCAN for template analysis
.env, .env.local, .env.production - SKIP by default (contain real secrets)
Note: Real .env files should never be committed to version control. The scanner analyzes .env.example templates to ensure proper documentation of required variables.
High Priority Locations
app.py, main.py, wsgi.py - Entry points
**/views.py, **/routes.py - Request handlers
**/api/**/*.py - API endpoints
**/auth*, **/login* - Authentication code
**/models.py - Database models
**/serializers.py - Data serialization
**/middleware.py - Middleware code
Framework-Specific
Flask:
app.py, __init__.py - Application factory
**/blueprints/** - Blueprint routes
templates/** - Jinja2 templates
Django:
settings.py, **/settings/*.py - Django settings
urls.py - URL configuration
**/views.py - View functions/classes
**/forms.py - Form definitions
templates/** - Django templates
FastAPI:
main.py - Application entry
**/routers/** - API routers
**/dependencies.py - Dependency injection
**/schemas.py - Pydantic models
Output Format
Findings should be reported as:
[SEVERITY] Category: Description
File: path/to/file.py:lineNumber
Code: <relevant code snippet>
Risk: <explanation of the security risk>
Fix: <recommended remediation>
Integration with CI/CD
This skill can generate output compatible with:
- GitHub Security Advisories
- SARIF format for GitHub Code Scanning
- JSON for custom integrations
- JUnit XML for CI pipelines
References
Load additional context as needed:
references/owasp-top-10.md - OWASP Top 10:2025 quick reference
references/python-vulnerabilities.md - Python-specific vulnerabilities
references/injection-patterns.md - Injection vulnerability patterns
references/deserialization.md - Insecure deserialization patterns
references/flask-security.md - Flask security guide
references/django-security.md - Django security guide
references/fastapi-security.md - FastAPI security guide
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: python-security-scan3description: Comprehensive security vulnerability scanner for Python projects including Flask, Django, and FastAPI applications. Detects OWASP Top 10 vulnerabilities, injection flaws, insecure deserialization, authentication issues, hardcoded secrets, and framework-specific security problems. Audits dependencies for known CVEs and generates actionable security reports. Use when this capability is needed.4---56# Python Security Scan Skill78This skill enables comprehensive security scanning of Python projects based on OWASP guidelines, Python security best practices, and framework-specific vulnerabilities.910## When to Use This Skill1112- Security audits of Python applications13- Code review for security vulnerabilities14- Pre-deployment security checks15- Dependency vulnerability assessment16- Detecting hardcoded secrets and credentials17- Framework-specific security reviews (Flask, Django, FastAPI)1819## Supported Frameworks2021This skill automatically detects and applies framework-specific checks for:2223- **Flask** - Template injection, session security, CORS, extensions24- **Django** - ORM injection, CSRF, template security, settings25- **FastAPI** - Dependency injection, Pydantic validation, OAuth226- **General Python** - Core language vulnerabilities applicable to all projects2728## Scan Types2930### 1. Quick Scan31Fast scan focusing on critical vulnerabilities:32- Hardcoded secrets, API keys, and credentials33- Dangerous function usage (`eval`, `exec`, `pickle.loads`)34- Command injection via `subprocess`, `os.system`35- SQL injection patterns36- Known vulnerable dependencies3738### 2. Full Scan39Comprehensive security assessment covering:40- All OWASP Top 10:2025 categories41- Python-specific vulnerabilities42- Framework-specific security issues43- Injection vulnerabilities (SQL, NoSQL, Command, LDAP)44- Insecure deserialization45- Authentication and authorization flaws46- Cryptographic failures47- Security misconfigurations48- Dependency audit (CVE check)49- Environment variable and secrets exposure5051### 3. Targeted Scan52Focus on specific vulnerability categories:53- `--injection` - SQL/NoSQL/Command/LDAP injection54- `--deserialization` - Pickle, YAML, JSON deserialization55- `--auth` - Authentication/authorization issues56- `--secrets` - Hardcoded credentials57- `--deps` - Dependency vulnerabilities58- `--crypto` - Cryptographic issues59- `--flask` - Flask-specific vulnerabilities60- `--django` - Django-specific vulnerabilities61- `--fastapi` - FastAPI-specific vulnerabilities6263## Scan Procedure6465### Step 1: Project Discovery661. Identify project type and framework:67 - Check for `requirements.txt`, `Pipfile`, `pyproject.toml`, `setup.py`68 - Detect Flask (`from flask import`), Django (`django.conf`), FastAPI (`from fastapi import`)692. Locate configuration files703. Map the codebase structure7172### Step 2: Framework Detection73```python74# Detection patterns75Flask: "from flask import", "Flask(__name__)"76Django: "django.conf.settings", "INSTALLED_APPS", "manage.py"77FastAPI: "from fastapi import", "FastAPI()"78```7980### Step 3: Dependency Audit81Run the dependency audit script:82```bash83./scripts/dependency-audit.sh /path/to/project84```85Or manually:86```bash87pip-audit88# or89safety check90```9192### Step 4: Secret Scanning93Scan for hardcoded secrets:94```bash95python scripts/secret-scanner.py /path/to/project96```9798**Important: Environment File Handling**99- By default, real `.env` files are **SKIPPED** (`.env`, `.env.local`, `.env.production`, etc.)100- These files contain actual secrets and should not be in version control101- Only `.env.example` and `.env.template` files are analyzed for documentation quality102- Use `--include-env-files` flag only if explicitly requested by user103104The scanner will:1051. Scan source code for hardcoded secrets1062. Analyze `.env.example` templates to check:107 - Which sensitive variables are documented108 - Whether variables have descriptions (comments)109 - If placeholder values look like real secrets110 - Suggestions for missing common variables (SECRET_KEY, DATABASE_URL, etc.)111112### Step 5: Pattern Analysis113For each file in the codebase, check against patterns in:114- `references/python-vulnerabilities.md` - Core Python issues115- `references/injection-patterns.md` - Injection flaws116- `references/deserialization.md` - Insecure deserialization117- `references/flask-security.md` - Flask vulnerabilities118- `references/django-security.md` - Django vulnerabilities119- `references/fastapi-security.md` - FastAPI vulnerabilities120121### Step 6: Report Generation122Generate a security report using:123- `assets/report-template.md` - Report structure124125## Severity Classification126127| Severity | Description | Action Required |128|----------|-------------|-----------------|129| CRITICAL | Exploitable vulnerability with severe impact | Immediate fix required |130| HIGH | Significant security risk | Fix before deployment |131| MEDIUM | Potential security issue | Fix in next release |132| LOW | Minor security concern | Consider fixing |133| INFO | Security best practice suggestion | Optional improvement |134135## Key Files to Scan136137### Always Check138- `**/*.py` - All Python source files139- `requirements.txt`, `Pipfile`, `pyproject.toml` - Dependencies140- `setup.py`, `setup.cfg` - Package configuration141- `config.py`, `settings.py` - Configuration files142- `**/secrets*`, `**/credentials*` - Obvious secret locations143144### Environment Files145- `.env.example`, `.env.template` - **SCAN** for template analysis146- `.env`, `.env.local`, `.env.production` - **SKIP** by default (contain real secrets)147148**Note:** Real `.env` files should never be committed to version control. The scanner analyzes `.env.example` templates to ensure proper documentation of required variables.149150### High Priority Locations151- `app.py`, `main.py`, `wsgi.py` - Entry points152- `**/views.py`, `**/routes.py` - Request handlers153- `**/api/**/*.py` - API endpoints154- `**/auth*`, `**/login*` - Authentication code155- `**/models.py` - Database models156- `**/serializers.py` - Data serialization157- `**/middleware.py` - Middleware code158159### Framework-Specific160**Flask:**161- `app.py`, `__init__.py` - Application factory162- `**/blueprints/**` - Blueprint routes163- `templates/**` - Jinja2 templates164165**Django:**166- `settings.py`, `**/settings/*.py` - Django settings167- `urls.py` - URL configuration168- `**/views.py` - View functions/classes169- `**/forms.py` - Form definitions170- `templates/**` - Django templates171172**FastAPI:**173- `main.py` - Application entry174- `**/routers/**` - API routers175- `**/dependencies.py` - Dependency injection176- `**/schemas.py` - Pydantic models177178## Output Format179180Findings should be reported as:181182```183[SEVERITY] Category: Description184 File: path/to/file.py:lineNumber185 Code: <relevant code snippet>186 Risk: <explanation of the security risk>187 Fix: <recommended remediation>188```189190## Integration with CI/CD191192This skill can generate output compatible with:193- GitHub Security Advisories194- SARIF format for GitHub Code Scanning195- JSON for custom integrations196- JUnit XML for CI pipelines197198## References199200Load additional context as needed:201- `references/owasp-top-10.md` - OWASP Top 10:2025 quick reference202- `references/python-vulnerabilities.md` - Python-specific vulnerabilities203- `references/injection-patterns.md` - Injection vulnerability patterns204- `references/deserialization.md` - Insecure deserialization patterns205- `references/flask-security.md` - Flask security guide206- `references/django-security.md` - Django security guide207- `references/fastapi-security.md` - FastAPI security guide208209---210> Converted and distributed by [TomeVault](https://tomevault.io/claim/sugarforever) — claim your Tome and manage your conversions.211<!-- tomevault:4.0:skill_md:2026-04-11 -->