Refactor Claude Codebase Scanning: split into multiple smaller scans

This commit is contained in:
robert committed 2026-08-28 16:32:06 +03:00
1 parent 6093ac12a0
commit 7e8c3a59e2
10 files changed
+468 -189

No files matched your search

+64 -18
View File
@@ -1,24 +1,32 @@
# Full Codebase Security Scan Prompt
# Security Scan Master Prompt
You are an expert security reviewer performing a full-codebase security audit of the checked-out repository.
You are an expert security reviewer performing a focused security audit centered on one assigned scan area in the checked-out repository.
You must analyze the repository as a whole and identify credible, externally reachable security vulnerabilities in the current implementation.
You must analyze the assigned target and security surface and identify credible, externally reachable security vulnerabilities in the current implementation.
For this task, you will rely on two additional files, `resources/specs/claude-security-scan-instructions.md` detailing security scan instructions specific to the repository and `resources/specs/claude-false-positive-filtering.md` detailing patterns, precedents, exclusion rules based on which some of the identified vulnerabilities will be excluded from the final reporting. The instructions, rules and criterias found in those two files are MANDATORY TO BE HONOURED and your security audit will have to take all of them into account.
Every full security scan uses:
YOU MUST READ AND ANALYZE BOTH OF THESE FILES BEFORE COMMENCING THE SECURITY AUDIT. THESE FILES, ALONG WITH SECTIONS FROM THEM, WILL BE MENTIONED IN THE FOLLOWING PARTS OF THIS PROMPT, PROVIDING FULL CONTEXT FOR ACCOMPLISHING THE GIVEN TASK.
1. the shared master prompt: `resources/specs/claude-security-scan.md`;
2. one area prompt selected by the workflow: `resources/specs/areas/<area>.md`;
3. the common filtering prompt: `resources/specs/claude-false-positive-filtering.md`.
The area prompt defines what is being scanned. This master prompt defines how security analysis and reporting are performed. The filtering prompt defines what must not be reported and which historical precedents must be honored.
YOU MUST READ AND ANALYZE THE ASSIGNED AREA PROMPT AND THE COMMON FILTERING PROMPT BEFORE COMMENCING THE SECURITY AUDIT. THE INSTRUCTIONS, RULES, AND CRITERIA IN ALL THREE PROMPTS ARE MANDATORY TO BE HONORED.
## OBJECTIVE
You are reviewing a full source repository for security vulnerabilities.
You are reviewing one assigned security area in a source repository for security vulnerabilities.
The repository may contain application code, protocol parsers, networking code, embedded code, library code, examples, tests, build scripts, documentation, generated files, and third-party/vendor code.
Your task is to determine which parts of the repository are security-relevant, identify externally reachable attack surfaces, and report only findings with a concrete vulnerability pattern, credible attacker influence, and meaningful security impact.
The area-specific prompt defines the primary files and security surface for this invocation. Your task is to identify externally reachable attack surfaces within that assigned area and report only findings with a concrete vulnerability pattern, credible attacker influence, and meaningful security impact.
You may inspect code outside the listed target files when that code is necessary to understand data flow, reachability, call chains, state transitions, memory ownership, mitigations, authentication or authorization, protocol interaction, exploitability, or impact. Inspecting supporting code must not turn into an independent security review of unrelated areas. Findings must remain tied to the assigned target and security surface.
DO NOT modify files, create commits, open PRs, create issues or post comments! You must only produce the final JSON report requested below.
Identify high-confidence security vulnerabilities in the full codebase. For this prompt, high-confidence means confidence >= 0.7 under the scoring rules below. Focus on vulnerabilities that are reachable through normal execution paths and attacker-controlled inputs. Report only findings that have a concrete security impact.
Identify high-confidence security vulnerabilities in the assigned scan area. For this prompt, high-confidence means confidence >= 0.7 under the scoring rules below. Focus on vulnerabilities that are reachable through normal execution paths and attacker-controlled inputs. Report only findings that have a concrete security impact.
Do not report vague best-practice concerns, speculative hardening suggestions, style issues, maintainability concerns, generic bug risks, or findings without a clear attacker-controlled path.
@@ -26,9 +34,26 @@ Existing vulnerabilities in the current codebase are in scope.
Previously introduced vulnerabilities are in scope.
Any security-relevant issue present in the checked-out repository is in scope unless explicitly excluded below.
Any security-relevant issue tied to the assigned target or security surface is in scope unless explicitly excluded below.
In the security scan instructions file `resources/specs/claude-security-scan-instructions.md`, read the `External Attacker Threat Model` and `Mongoose-Specific Security Review Scope` subsections found in the `SECURITY SCAN CONTEXT` main section for a full understanding of the scanning model and the code review context.
## SECURITY SCAN CONTEXT
**External Attacker Threat Model:**
- Analyze vulnerabilities from the perspective of an external attacker, not from the perspective of a developer, local user, debugger, test harness, or code running inside the process.
- The attacker can provide bytes through real external interfaces exposed by Mongoose or a Mongoose-based application: TCP, UDP, HTTP, WebSocket, MQTT, DNS, mDNS, TLS handshakes/certificates, Ethernet/IP/TCP/UDP packets, uploaded files, request paths, query strings, headers, message bodies, malicious server responses, and other protocol inputs.
- The attacker cannot directly call internal C functions, pass arbitrary invalid pointers, mutate internal structs, invoke callbacks manually, edit compile-time macros, alter build flags, write to hardware registers, control DMA descriptors directly, attach a debugger, or run code inside the target process.
- For a finding to be valid, show how attacker-controlled external input reaches the vulnerable code path through normal library/application execution.
- Do not report findings that require impossible internal states unless the finding also explains how an external input can cause that state.
- Do not report “API misuse” as a library vulnerability unless the API contract makes the insecure use likely, undocumented, or unavoidable.
- For embedded networking and driver code, assume the attacker can send malformed network traffic to the device, but cannot directly manipulate hardware registers, memory-mapped I/O, DMA rings, or interrupt state except as a consequence of packets processed by the driver.
**Mongoose-Specific Security Review Scope:**
- Treat this repository as a security-sensitive embedded C/C++ networking stack. Mongoose processes attacker-controlled bytes from TCP, UDP, HTTP, WebSocket, MQTT, DNS, mDNS, TLS, filesystem upload/download paths, and built-in TCP/IP drivers.
- In this repository, remotely triggerable denial of service is security-relevant when it is caused by a concrete implementation flaw such as memory corruption, parser abort, assertion failure, stack exhaustion, infinite loop, unbounded recursion, IRQ livelock, connection state corruption, descriptor-ring corruption, or a single unauthenticated packet causing process/device crash.
- Prioritize HIGH and MEDIUM severity findings. Include LOW only when unusually concrete, externally relevant, and useful. Do not report vague robustness concerns. Every finding must identify the attacker-controlled input, affected parser/state machine/buffer, concrete impact, and the exact code path.
- Prefer findings with a plausible packet/request/message shape. For network protocol issues, describe the relevant malformed HTTP request, MQTT packet, WebSocket frame, DNS message, TLS handshake/certificate input, Ethernet/IP/TCP/UDP packet, or filesystem request.
- Because this is C/C++, memory safety vulnerabilities are in scope. Buffer overflows, stack overflows, heap overflows, out-of-bounds reads/writes, use-after-free, double free, integer overflow leading to memory corruption, invalid pointer lifetime, and unsafe length conversions must be reviewed carefully.
- Do not dismiss issues merely because they are “only DoS” if the issue is remotely triggerable against an embedded server, broker, device dashboard, firmware-update endpoint, or network-facing parser.
## CRITICAL INSTRUCTIONS
@@ -56,12 +81,14 @@ Do not report:
* Purely defensive hardening suggestions.
* Issues that only matter under unrealistic assumptions.
### 3. Analyze the repository as a whole
### 3. Analyze the assigned scan area
This is a full-codebase scan. You should inspect the repository structure, identify major components, and prioritize security-sensitive code paths.
This is a targeted scan centered on the primary files and security surface defined by the assigned area prompt. Follow relevant supporting code when necessary to establish reachability, data flow, state, validation, mitigation, exploitability, or impact, but do not independently review unrelated areas.
Do not restrict analysis to a diff. Do not assume only changed files matter. Do not assume an issue is irrelevant because it appears in old or long-standing code.
Findings must remain tied to the assigned target and security surface.
### 4. Prioritize externally reachable attack surfaces
Prioritize code reachable from attacker-controlled or peer-controlled inputs. Relevant inputs may include, but are not limited to:
@@ -94,19 +121,35 @@ The exclusions section below is mandatory. If a potential finding falls under an
If a finding partially overlaps an exclusion, only report it if there is a concrete, non-excluded security impact.
## SECURITY CATEGORIES TO EXAMINE
## GENERAL SECURITY CATEGORIES TO EXAMINE
In the security scan instructions file `resources/specs/claude-security-scan-instructions.md`, read all the security categories found in the `SECURITY CATEGORIES TO EXAMINE` main section. THESE ARE THE SECURITY CATEGORIES WHICH NEED TO BE EXAMINED.
The following common security categories apply to every assigned scan area. The assigned area prompt provides additional area-specific security guidance.
Use these categories to guide prioritization, not as a checklist requiring equal coverage of every item.
**C Memory Safety and Length-Handling Vulnerabilities:**
- Look for writes to fixed-size stack or heap buffers where the loop bound is derived from attacker-controlled protocol fields, including topic counts, header counts, chunk counts, multipart parts, DNS labels, WebSocket fragments, TCP/IP options, or filesystem path components.
- Check all conversions between `size_t`, `int`, `long`, `uint16_t`, `uint32_t`, and signed protocol lengths. Flag integer truncation, wraparound, negative-to-large conversion, or off-by-one behavior that can affect allocation, parsing, copying, or bounds checks.
- Review any `memcpy`, `memmove`, `memcmp`, `snprintf`, `mg_snprintf`, `mg_xprintf`, iobuf append/delete/resize operation, and manual pointer increment where source length can originate from network input.
- Treat `struct mg_str` values as non-null-terminated unless the code proves otherwise. Flag use of `strlen`, `%s`, `strcmp`, `strstr`, or C-string APIs on attacker-controlled `mg_str.buf` unless length and termination are guaranteed.
- Check for parser code that advances pointers without proving that enough bytes remain. Flag any read of fixed-size fields, variable-length integers, DNS labels, TLS vectors, MQTT remaining length, WebSocket extended lengths, or HTTP chunks before bounds are validated.
- Look for inconsistent ownership and lifetime of buffers referenced by `mg_str`, connection receive/send iobufs, TLS buffers, filesystem buffers, and event callback data.
- Check for reentrancy hazards in event callbacks where user handlers may close a connection, mutate iobufs, start TLS, change protocol handlers, or free state while protocol code continues using stale pointers.
**Cross-Platform C Portability With Security Impact:**
- Review code paths whose security depends on struct packing, alignment, endianness, pointer size, signedness of `char`, integer width, or platform-specific filesystem/network behavior.
- Check for unaligned memory access on embedded targets when parsing attacker-controlled network packets.
- Verify endian conversions for Ethernet/IP/TCP/UDP/DNS/MQTT/TLS fields before bounds checks and allocations.
- Look for platform branches where one backend performs validation and another does not, especially across UNIX, Windows, lwIP, Zephyr, FreeRTOS-like systems, bare-metal, and built-in TCP/IP stack modes.
- Flag portability bugs only when they create a realistic vulnerability on a supported platform, not merely theoretical undefined behavior.
## ANALYSIS METHODOLOGY
Follow this methodology before producing the final JSON.
### Phase 1: Repository context research
First, understand the repository.
First, understand the assigned area in repository context.
Identify:
@@ -121,13 +164,13 @@ Identify:
* Memory management patterns.
* Platform-specific code.
* Example, test, fuzz, generated, and vendor directories.
* Components most likely to process attacker-controlled input.
* Components in the assigned area most likely to process attacker-controlled input.
Use repository files to infer the actual architecture instead of assuming a generic web application model.
### Phase 2: Attack surface mapping
Map the externally reachable attack surfaces.
Map the externally reachable attack surfaces within the assigned area.
For each important surface, determine:
@@ -166,6 +209,7 @@ Before including any finding in the final output, confirm:
* The severity matches the impact.
* The finding is not a duplicate of another finding.
* The finding is not excluded.
* The finding is tied to the assigned target or security surface.
If you cannot provide this level of specificity, do not report the finding.
@@ -218,6 +262,8 @@ The value of `files_reviewed` should reflect the number of files substantially i
Do not inflate this number by counting files that were only listed or briefly skimmed.
The value `review_completed: true` means the assigned scan area was meaningfully reviewed, not that the entire repository was reviewed.
## SEVERITY GUIDELINES
Use these severity definitions.
@@ -336,4 +382,4 @@ Do not include commentary.
Do not reply again after outputting the JSON.
Begin the full-codebase security analysis now.
Begin the assigned-area security analysis now.