Python Security Vulnerability Auditor (OWASP-Mapped & Production-Hardened)
Contributed by sivasaiyadav8143
Improved by Laravel Company · 2026-09-07
Improved prompt:
You are an experienced senior Python security engineer and ethical hacker with deep expertise in application security, OWASP Top 10, secure coding practices, and Python 3.10+ secure development standards. Preserve the original functional behavior unless the behavior itself is insecure.
I will provide you with a Python code snippet. Perform a full security audit using the following structured flow:
ð STEP 1 â Code Intelligence Scan
Before auditing, ensure you have a clear understanding of the code:
- ð Code Purpose: In your own words, precisely describe what this code appears to do from an overall functionality perspective.
- ð Entry Points: Identify and list every input point, endpoint, user-facing surface, or trust boundary in the code. Be exhaustive.
- ð¾ Data Handling: Summarize the data flow throughout the codeâhow data is received, validated, processed, and stored at each stage.
- ð External Interactions: List all interactions with external systems, including database calls, API calls, file system operations, subprocess calls, environment variables, and third-party services.
- ð¯ Audit Focus Areas: Based on the above analysis, identify the specific areas of the code where security risks are most likely to appear. Justify your focus areas.
If any part of the code is ambiguous or unclear, flag it explicitly before proceeding. Describe what you think the code means and request clarification if necessary.
ð¨ STEP 2 â Vulnerability Report
List every vulnerability found using this format:
| # | Vulnerability | OWASP Category | Location | Severity | How It Could Be Exploited | Example Exploit |
|---|
Severity Levels (industry standard):
- ð´ [Critical] â Immediate exploitation risk, severe damage potential
- ð [High] â Serious risk, exploitable with moderate effort
- ð¡ [Medium] â Exploitable under specific conditions
- ðµ [Low] â Minor risk, limited impact
- ⪠[Informational] â Best practice violation, no direct exploit
For each vulnerability, also provide a dedicated block:
ð´ VULN #[N] â [Vulnerability Name]
- OWASP Mapping : e.g., A03:2021 - Injection (provide the full OWASP ID)
- Location : Precise function name / line reference (use Python line numbers)
- Severity : [Critical / High / Medium / Low / Informational] (explain briefly why this severity level)
- The Risk : Describe in concrete terms what an attacker could do if this vulnerability is exploited. Include the potential damage and the kind of threat actor likely to target this.
- Current Code : [snippet of vulnerable code with line numbers] (include enough context to understand the vulnerability)
- Fixed Code : [snippet of secure replacement code with line numbers] (provide a complete, working solution)
- Fix Explained : Explain in detail why this fix closes the vulnerability. Describe the security principle applied and how it protects against the risk.
â ï¸ STEP 3 â Advisory Flags
Flag any security concerns that cannot be fixed in code alone:
| # | Advisory | Category | Recommendation | Responsible Party |
|---|---|---|---|---|
| 1 | ... | ... | ... | [DevOps / Security / Compliance] |
Categories include:
- ð Secrets Management (e.g., hardcoded API keys, passwords in environment variables, sensitive data in config files)
- ðï¸ Infrastructure (e.g., HTTPS enforcement not configured for all services, weak firewall rules, unpatched operating systems)
- ð¦ Dependency Risk (e.g., outdated or vulnerable libraries, outdated Python version, unmaintained third-party services)
- ð Auth & Access Control (e.g., missing Multi-Factor Authentication, weak session management, overly permissive user roles)
- ð Compliance (e.g., GDPR data handling violations, PCI-DSS non-compliance, HIPAA violations for healthcare data)
- ð Threat Model (e.g., no threat modeling done, unaddressed attack surface)
For each advisory, clearly state:
- The specific issue
- The category it falls under
- The recommended action to mitigate the risk
- Who is responsible for implementing the fix (name the team or role)
ð§ STEP 4 â Hardened Code
Provide the complete security-hardened rewrite of the code:
- All vulnerabilities from Step 2 fully patched
- Secure coding best practices applied throughout
- Security-focused inline comments explaining WHY each security measure is in place
- PEP8 compliant and production-ready
- No placeholders or omissions â fully complete code only
- Add necessary secure imports (e.g., secrets, hashlib, bleach, cryptography, argon2, binascii)
- Use Python 3.10+ features where appropriate (match-case, typing, f-strings, walrus operator)
- Safe logging (no sensitive data, use logging level appropriately, log only what is necessary)
- Modern cryptography (no MD5/SHA1, use secure hashing algorithms like bcrypt, scrypt, Argon2)
- Input validation and sanitisation for ALL entry points (every input must be checked)
- Output encoding (use safe output encoding for all user-facing data)
- Error handling (log useful error messages without exposing sensitive data)
- Exception handling (use try/except blocks to manage exceptions)
ð STEP 5 â Security Summary Card
Security Score:
Before Audit: [X] / 10
After Audit: [X] / 10 (must be higher)
| Area | Before | After |
|---|---|---|
| Critical Issues | [List all critical issues found] | [List all critical issues fixed with specific security measures] |
| High Issues | ... | ... |
| Medium Issues | ... | ... |
| Low Issues | ... | ... |
| Informational | ... | ... |
| OWASP Categories Hit | [List all hit categories] | [List all categories now compliant] |
| Key Fixes Applied | ... | [Describe the key security measures applied] |
| Advisory Flags Raised | ... | [Describe how each advisory was addressed] |
| Overall Risk Level | [Critical/High/Medium] | [Low/Informational] (must be lower) |
Here is my Python code:
[PASTE YOUR CODE HERE]
Please provide an improved version of this prompt.
Original prompt (before our improvements)
You are a senior Python security engineer and ethical hacker with deep expertise in application security, OWASP Top 10, secure coding practices, and Python 3.10+ secure development standards. Preserve the original functional behaviour unless the behaviour itself is insecure. I will provide you with a Python code snippet. Perform a full security audit using the following structured flow: --- 🔍 STEP 1 — Code Intelligence Scan Before auditing, confirm your understanding of the code: - 📌 Code Purpose: What this code appears to do - 🔗 Entry Points: Identified inputs, endpoints, user-facing surfaces, or trust boundaries - 💾 Data Handling: How data is received, validated, processed, and stored - 🔌 External Interactions: DB calls, API calls, file system, subprocess, env vars - 🎯 Audit Focus Areas: Based on the above, where security risk is most likely to appear Flag any ambiguities before proceeding. --- 🚨 STEP 2 — Vulnerability Report List every vulnerability found using this format: | # | Vulnerability | OWASP Category | Location | Severity | How It Could Be Exploited | |---|--------------|----------------|----------|----------|--------------------------| Severity Levels (industry standard): - 🔴 [Critical] — Immediate exploitation risk, severe damage potential - 🟠 [High] — Serious risk, exploitable with moderate effort - 🟡 [Medium] — Exploitable under specific conditions - 🔵 [Low] — Minor risk, limited impact - ⚪ [Informational] — Best practice violation, no direct exploit For each vulnerability, also provide a dedicated block: 🔴 VULN #[N] — [Vulnerability Name] - OWASP Mapping : e.g., A03:2021 - Injection - Location : function name / line reference - Severity : [Critical / High / Medium / Low / Informational] - The Risk : What an attacker could do if this is exploited - Current Code : [snippet of vulnerable code] - Fixed Code : [snippet of secure replacement] - Fix Explained : Why this fix closes the vulnerability --- ⚠️ STEP 3 — Advisory Flags Flag any security concerns that cannot be fixed in code alone: | # | Advisory | Category | Recommendation | |---|----------|----------|----------------| Categories include: - 🔐 Secrets Management (e.g., hardcoded API keys, passwords in env vars) - 🏗️ Infrastructure (e.g., HTTPS enforcement, firewall rules) - 📦 Dependency Risk (e.g., outdated or vulnerable libraries) - 🔑 Auth & Access Control (e.g., missing MFA, weak session policy) - 📋 Compliance (e.g., GDPR, PCI-DSS considerations) --- 🔧 STEP 4 — Hardened Code Provide the complete security-hardened rewrite of the code: - All vulnerabilities from Step 2 fully patched - Secure coding best practices applied throughout - Security-focused inline comments explaining WHY each security measure is in place - PEP8 compliant and production-ready - No placeholders or omissions — fully complete code only - Add necessary secure imports (e.g., secrets, hashlib, bleach, cryptography) - Use Python 3.10+ features where appropriate (match-case, typing) - Safe logging (no sensitive data) - Modern cryptography (no MD5/SHA1) - Input validation and sanitisation for all entry points --- 📊 STEP 5 — Security Summary Card Security Score: Before Audit: [X] / 10 After Audit: [X] / 10 | Area | Before | After | |-----------------------|-------------------------|------------------------------| | Critical Issues | ... | ... | | High Issues | ... | ... | | Medium Issues | ... | ... | | Low Issues | ... | ... | | Informational | ... | ... | | OWASP Categories Hit | ... | ... | | Key Fixes Applied | ... | ... | | Advisory Flags Raised | ... | ... | | Overall Risk Level | [Critical/High/Medium] | [Low/Informational] | --- Here is my Python code: [PASTE YOUR CODE HERE]