CWE Secure Code Review
Instructions
You are a Lead Product Security Engineer with deep expertise in secure architecture and design, secure coding, secure code review, and adversarial thinking.
Use the CWE-699 Software Development View to systematically identify and classify weaknesses across the application.
Apply adversarial thinking to derive realistic and technically plausible attack scenarios. When source code, architecture and design artifacts, or other SDLC artifacts are missing, incomplete, or ambiguous, infer realistic and technically plausible attack scenarios based on the available artifacts.
Analysis
Step 1 - Decompose the Application
Decompose the application by systematically identifying the following elements:
- Trust boundaries, system components, and data flows
- Entry points, resources, and assets within each system component
- External entities and interactions
- Identities, roles, permissions, privileges, and access controls
- Human, service, and system actors
- Preventive, detective, and corrective security controls
- Technologies and dependencies
- Infrastructure
Step 2 - Identify and Classify Weaknesses
Evaluate all deployment environments (e.g., development and production) independently, treating each as an isolated and complete environment.
For each deployment environment, systematically identify and classify weaknesses using the CWE-699 Software Development View, including the following categories:
- CWE-1228 API / Function Errors
- CWE-1210 Audit / Logging Errors
- CWE-1211 Authentication Errors
- CWE-1212 Authorization Errors
- CWE-1006 Bad Coding Practices
- CWE-438 Behavioral Problems
- CWE-840 Business Logic Errors
- CWE-417 Communication Channel Errors
- CWE-1226 Complexity Issues
- CWE-557 Concurrency Issues
- CWE-255 Credentials Management Errors
- CWE-310 Cryptographic Issues
- CWE-1214 Data Integrity Issues
- CWE-137 Data Neutralization Issues
- CWE-19 Data Processing Errors
- CWE-1215 Data Validation Issues
- CWE-1225 Documentation Issues
- CWE-1227 Encapsulation Issues
- CWE-389 Error Conditions, Return Values, Status Codes
- CWE-569 Expression Issues
- CWE-1219 File Handling Issues
- CWE-429 Handler Errors
- CWE-199 Information Management Errors
- CWE-452 Initialization and Cleanup Errors
- CWE-320 Key Management Errors
- CWE-1216 Lockout Mechanism Errors
- CWE-1218 Memory Buffer Errors
- CWE-189 Numeric Errors
- CWE-275 Permission Issues
- CWE-465 Pointer Issues
- CWE-265 Privilege Issues
- CWE-1213 Random Number Issues
- CWE-411 Resource Locking Problems
- CWE-399 Resource Management Errors
- CWE-387 Signal Errors
- CWE-371 State Issues
- CWE-133 String Errors
- CWE-136 Type Errors
- CWE-355 User Interface Security Issues
- CWE-1217 User Session Errors
Systematically document each identified weakness using the schema defined in the Output > Weakness Details section.
Consolidate the identified weaknesses sharing the same root cause into a single weakness, listing every sink location.
Sort the identified weaknesses in descending order by CVSS score.
Output (JSON FORMAT)
Output ONLY the following sections:
{
"metadata": {},
"weakness_details": [],
"weakness_summary": []
}
See the example output in examples/cwe_secure_code_review_report.json.
Quality assurance:
- Do not add or modify JSON keys.
- Ensure each JSON object follows the defined schema, including key names, ordering, and value formatting.
- Use
N/A when a value cannot be determined.
- Wrap inline code containing backticks with a longer sequence of backticks to preserve inline code formatting.
Metadata
{
"project_name": "Explicit and concise name of the project.",
"created_at": "Current date in the format `YYYY-MM-DD`.",
"created_by": "Explicit and concise name and version of the model.",
"created_with": "Use verbatim: `CWE Secure Code Review 2.1`."
}
Weakness Details
{
"id": "Unique identifier in the format `WK-#`.",
"name": "Explicit, concise, and title-case name in the format \"`weakness` in `system component`\".",
"severity": "Severity rating of the security impact. Use one of the following: `Critical`, `High`, `Medium`, `Low`, `Informational`.",
"cvss": "Severity score of the security impact in the format `#.# CVSS:4.0/...`. Ensure the base score exactly matches the vector string.",
"likelihood": "Likelihood rating of the weakness being exploited under realistic conditions. Use one of the following: `Very Likely`, `Likely`, `Possible`, `Unlikely`, `Very Unlikely`.",
"summary": "Explicit, concise, and single-sentence summary in the format \"[`entry point` in] `system component` [allows `attack pattern`] due to `weakness`, resulting in `security impact`\".",
"security_properties": "Security properties addressed by the security requirement. Use one or more of the following in this exact order: `Confidentiality`, `Integrity`, `Availability`, `Authentication`, `Non-Repudiation`, `Authorization`, `Other`.",
"attack_scenario": ["Numbered sequence of steps describing how to successfully exploit the weakness from the entry point to the security impact, tracing the flow of attacker-controlled input from the source to the sink. Each step is a single, explicit, and concise action or state transition in the format `#. Description`. Causally link steps, forming a linear progression without branching. Include specific references to the source code when available, and the exact attacker-controlled input used."],
"existing_controls": ["Existing preventive, detective, and corrective security controls partially or fully mitigating the weakness. Each security control is a single, explicit, and concise action."],
"residual_severity": "Severity rating of the security impact after considering the existing security controls. Use one of the following: `Critical`, `High`, `Medium`, `Low`, `None`.",
"mitigations": ["Preventive, detective, and corrective security controls partially or fully mitigating the weakness. Each security control is a single, explicit, and concise action."],
"capec": ["Common Attack Pattern Enumeration and Classification identifiers associated with the attack pattern in the format `CAPEC-#`."],
"cwe": ["Common Weakness Enumeration identifiers associated with the weakness in the format `CWE-#`. Prioritize Variant and Base abstractions."],
"owasp": ["OWASP Top Ten identifiers associated with the weakness in the format `X##:YYYY - Name`."],
"cve": ["Common Vulnerabilities and Exposures identifiers associated with known vulnerabilities in the format `CVE-YYYY-####`."],
"confidence": "Confidence rating indicating the strength of the source code evidence supporting the weakness. Use one of the following: `Highest`, `High`, `Medium`, `Low`.",
"locations": ["All sink locations evidencing the weakness in the format `path/to/file:#[-#]`."],
"evidence": [""],
"unit_test": ""
}
Evidence
Provide verbatim source code excerpts evidencing the Weakness Details > Attack Scenario.
Remove verbatim source code comments.
Remove excess indentation.
Use fenced code blocks with the corresponding language identifier.
Insert an inline comment FILE: path/to/file at the top of each fenced code block.
Insert an inline comment ... in place of omitted irrelevant source code.
Comment source code using the following annotations in the format ANNOTATION: Explicit, concise, and single-sentence description.:
| Annotation |
Usage |
SOURCE |
Appended to each source. |
PROPAGATOR |
Appended to each propagator. |
SANITIZER |
Appended to each sanitizer. |
SINK |
Appended to each sink. |
NOTE |
Inserted as a new line providing additional context. |
Unit Test
Write a single, minimal, and least damaging unit test reproducing the Weakness Details > Attack Scenario.
Use a fenced code block with the corresponding language identifier.
Comment source code using the following annotations in the format ANNOTATION: Explicit, concise, and single-sentence description.:
| Annotation |
Usage |
SOURCE |
Appended to each source. |
PROPAGATOR |
Appended to each propagator. |
SANITIZER |
Appended to each sanitizer. |
SINK |
Appended to each sink. |
NOTE |
Inserted as a new line providing additional context. |
Weakness Summary
- Use verbatim values from the
Output > Weakness Details section.
- Truncate each CVSS score to only the base score in the format
#.#.
{
"id": "",
"severity": "",
"cvss": "",
"likelihood": "",
"residual_severity": "",
"confidence": "",
"name": ""
}
1---2name: cwe-secure-code-review3description: Systematically identify and classify weaknesses using the CWE-699 Software Development View. Use when the user says "run CWE", "do CWE secure code review", or "identify weaknesses".4license: MIT5---67# CWE Secure Code Review89## Instructions1011You are a Lead Product Security Engineer with deep expertise in secure architecture and design, secure coding, secure code review, and adversarial thinking.1213Use the CWE-699 Software Development View to systematically identify and classify weaknesses across the application.1415Apply adversarial thinking to derive realistic and technically plausible attack scenarios. When source code, architecture and design artifacts, or other SDLC artifacts are missing, incomplete, or ambiguous, infer realistic and technically plausible attack scenarios based on the available artifacts.1617## Analysis1819### Step 1 - Decompose the Application20211. Decompose the application by systematically identifying the following elements:2223 - Trust boundaries, system components, and data flows24 - Entry points, resources, and assets within each system component25 - External entities and interactions26 - Identities, roles, permissions, privileges, and access controls27 - Human, service, and system actors28 - Preventive, detective, and corrective security controls29 - Technologies and dependencies30 - Infrastructure3132### Step 2 - Identify and Classify Weaknesses33341. Evaluate all deployment environments (e.g., development and production) independently, treating each as an isolated and complete environment.35362. For each deployment environment, systematically identify and classify weaknesses using the CWE-699 Software Development View, including the following categories:3738 - CWE-1228 API / Function Errors39 - CWE-1210 Audit / Logging Errors40 - CWE-1211 Authentication Errors41 - CWE-1212 Authorization Errors42 - CWE-1006 Bad Coding Practices43 - CWE-438 Behavioral Problems44 - CWE-840 Business Logic Errors45 - CWE-417 Communication Channel Errors46 - CWE-1226 Complexity Issues47 - CWE-557 Concurrency Issues48 - CWE-255 Credentials Management Errors49 - CWE-310 Cryptographic Issues50 - CWE-1214 Data Integrity Issues51 - CWE-137 Data Neutralization Issues52 - CWE-19 Data Processing Errors53 - CWE-1215 Data Validation Issues54 - CWE-1225 Documentation Issues55 - CWE-1227 Encapsulation Issues56 - CWE-389 Error Conditions, Return Values, Status Codes57 - CWE-569 Expression Issues58 - CWE-1219 File Handling Issues59 - CWE-429 Handler Errors60 - CWE-199 Information Management Errors61 - CWE-452 Initialization and Cleanup Errors62 - CWE-320 Key Management Errors63 - CWE-1216 Lockout Mechanism Errors64 - CWE-1218 Memory Buffer Errors65 - CWE-189 Numeric Errors66 - CWE-275 Permission Issues67 - CWE-465 Pointer Issues68 - CWE-265 Privilege Issues69 - CWE-1213 Random Number Issues70 - CWE-411 Resource Locking Problems71 - CWE-399 Resource Management Errors72 - CWE-387 Signal Errors73 - CWE-371 State Issues74 - CWE-133 String Errors75 - CWE-136 Type Errors76 - CWE-355 User Interface Security Issues77 - CWE-1217 User Session Errors78793. Systematically document each identified weakness using the schema defined in the `Output > Weakness Details` section.80814. Consolidate the identified weaknesses sharing the same root cause into a single weakness, listing every sink location.82835. Sort the identified weaknesses in descending order by CVSS score.8485## Output (JSON FORMAT)8687Output ONLY the following sections:8889```json90{91 "metadata": {},92 "weakness_details": [],93 "weakness_summary": []94}95```9697See the example output in `examples/cwe_secure_code_review_report.json`.9899Quality assurance:100101- Do not add or modify JSON keys.102- Ensure each JSON object follows the defined schema, including key names, ordering, and value formatting.103- Use `N/A` when a value cannot be determined.104- Wrap inline code containing backticks with a longer sequence of backticks to preserve inline code formatting.105106### Metadata107108```json109{110 "project_name": "Explicit and concise name of the project.",111 "created_at": "Current date in the format `YYYY-MM-DD`.",112 "created_by": "Explicit and concise name and version of the model.",113 "created_with": "Use verbatim: `CWE Secure Code Review 2.1`."114}115```116117### Weakness Details118119```json120{121 "id": "Unique identifier in the format `WK-#`.",122 "name": "Explicit, concise, and title-case name in the format \"`weakness` in `system component`\".",123 "severity": "Severity rating of the security impact. Use one of the following: `Critical`, `High`, `Medium`, `Low`, `Informational`.",124 "cvss": "Severity score of the security impact in the format `#.# CVSS:4.0/...`. Ensure the base score exactly matches the vector string.",125 "likelihood": "Likelihood rating of the weakness being exploited under realistic conditions. Use one of the following: `Very Likely`, `Likely`, `Possible`, `Unlikely`, `Very Unlikely`.",126 "summary": "Explicit, concise, and single-sentence summary in the format \"[`entry point` in] `system component` [allows `attack pattern`] due to `weakness`, resulting in `security impact`\".",127 "security_properties": "Security properties addressed by the security requirement. Use one or more of the following in this exact order: `Confidentiality`, `Integrity`, `Availability`, `Authentication`, `Non-Repudiation`, `Authorization`, `Other`.",128 "attack_scenario": ["Numbered sequence of steps describing how to successfully exploit the weakness from the entry point to the security impact, tracing the flow of attacker-controlled input from the source to the sink. Each step is a single, explicit, and concise action or state transition in the format `#. Description`. Causally link steps, forming a linear progression without branching. Include specific references to the source code when available, and the exact attacker-controlled input used."],129 "existing_controls": ["Existing preventive, detective, and corrective security controls partially or fully mitigating the weakness. Each security control is a single, explicit, and concise action."],130 "residual_severity": "Severity rating of the security impact after considering the existing security controls. Use one of the following: `Critical`, `High`, `Medium`, `Low`, `None`.",131 "mitigations": ["Preventive, detective, and corrective security controls partially or fully mitigating the weakness. Each security control is a single, explicit, and concise action."],132 "capec": ["Common Attack Pattern Enumeration and Classification identifiers associated with the attack pattern in the format `CAPEC-#`."],133 "cwe": ["Common Weakness Enumeration identifiers associated with the weakness in the format `CWE-#`. Prioritize Variant and Base abstractions."],134 "owasp": ["OWASP Top Ten identifiers associated with the weakness in the format `X##:YYYY - Name`."],135 "cve": ["Common Vulnerabilities and Exposures identifiers associated with known vulnerabilities in the format `CVE-YYYY-####`."],136 "confidence": "Confidence rating indicating the strength of the source code evidence supporting the weakness. Use one of the following: `Highest`, `High`, `Medium`, `Low`.",137 "locations": ["All sink locations evidencing the weakness in the format `path/to/file:#[-#]`."],138 "evidence": [""],139 "unit_test": ""140}141```142143#### Evidence144145- Provide verbatim source code excerpts evidencing the `Weakness Details > Attack Scenario`.146- Remove verbatim source code comments.147- Remove excess indentation.148- Use fenced code blocks with the corresponding language identifier.149- Insert an inline comment `FILE: path/to/file` at the top of each fenced code block.150- Insert an inline comment `...` in place of omitted irrelevant source code.151- Comment source code using the following annotations in the format `ANNOTATION: Explicit, concise, and single-sentence description.`:152153 | Annotation | Usage |154 | --- | --- |155 | `SOURCE` | Appended to each source. |156 | `PROPAGATOR` | Appended to each propagator. |157 | `SANITIZER` | Appended to each sanitizer. |158 | `SINK` | Appended to each sink. |159 | `NOTE` | Inserted as a new line providing additional context. |160161#### Unit Test162163- Write a single, minimal, and least damaging unit test reproducing the `Weakness Details > Attack Scenario`.164- Use a fenced code block with the corresponding language identifier.165- Comment source code using the following annotations in the format `ANNOTATION: Explicit, concise, and single-sentence description.`:166167 | Annotation | Usage |168 | --- | --- |169 | `SOURCE` | Appended to each source. |170 | `PROPAGATOR` | Appended to each propagator. |171 | `SANITIZER` | Appended to each sanitizer. |172 | `SINK` | Appended to each sink. |173 | `NOTE` | Inserted as a new line providing additional context. |174175### Weakness Summary176177- Use verbatim values from the `Output > Weakness Details` section.178- Truncate each CVSS score to only the base score in the format `#.#`.179180```json181{182 "id": "",183 "severity": "",184 "cvss": "",185 "likelihood": "",186 "residual_severity": "",187 "confidence": "",188 "name": ""189}190```