mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-20 19:41:58 +00:00
Refactor Claude Codebase Scanning: split into multiple smaller scans
This commit is contained in:
1 parent
6093ac12a0
commit
7e8c3a59e2
10 files changed
+468
-189
No files matched your search
@@ -0,0 +1,38 @@
|
||||
# Security Scan Area: common_misc
|
||||
|
||||
## Target
|
||||
|
||||
Area: common_misc
|
||||
|
||||
This area covers common utility code, parsing/string/formatting helpers, URL handling, hash/base64 helpers, filesystem backends, little filesystem integration, and flash support.
|
||||
|
||||
Primary files:
|
||||
- `src/base64.c`
|
||||
- `src/fmt.c`
|
||||
- `src/json.c`
|
||||
- `src/log.c`
|
||||
- `src/md5.c`
|
||||
- `src/printf.c`
|
||||
- `src/sha1.c`
|
||||
- `src/sha256.c`
|
||||
- `src/str.c`
|
||||
- `src/url.c`
|
||||
- `src/util.c`
|
||||
- `src/fs*.c`
|
||||
- `src/lfs.c`
|
||||
- `src/flash.c`
|
||||
|
||||
Perform a focused security review centered on these files and this security surface.
|
||||
|
||||
Supporting code outside these files may be inspected when necessary to establish reachability, data flow, state, validation, mitigation, or impact, but do not independently review unrelated areas.
|
||||
|
||||
## Area-Specific Security Guidance
|
||||
|
||||
**Filesystem Backends:**
|
||||
- Review packed filesystem code and filesystem backends for traversal, unauthorized file read/write, overwrite, or truncation.
|
||||
- Check path canonicalization across POSIX, Windows, embedded filesystems, packed filesystems, and custom `mg_fs` implementations.
|
||||
- Look for trailing slash confusion, NUL byte truncation, and case sensitivity differences in backend path handling.
|
||||
|
||||
**URL Parsing:**
|
||||
- Review URL parsing for scheme, host, port, IPv6 literal, userinfo, percent-encoding, embedded NUL, empty host, default port, and path/query boundary confusion.
|
||||
- Check for SSRF-relevant behavior only when attacker input can control the destination host, protocol, or network boundary. Path-only control is not sufficient.
|
||||
@@ -0,0 +1,30 @@
|
||||
# Security Scan Area: mongoose_core
|
||||
|
||||
## Target
|
||||
|
||||
Area: mongoose_core
|
||||
|
||||
This area covers the core event/network/connection machinery, iobuf handling, queues, socket transport, timers, and BSD abstraction.
|
||||
|
||||
Primary files:
|
||||
- `src/event.c`
|
||||
- `src/iobuf.c`
|
||||
- `src/net.c`
|
||||
- `src/queue.c`
|
||||
- `src/sock.c`
|
||||
- `src/timer.c`
|
||||
- `src/bsd.c`
|
||||
|
||||
Perform a focused security review centered on these files and this security surface.
|
||||
|
||||
Supporting code outside these files may be inspected when necessary to establish reachability, data flow, state, validation, mitigation, or impact, but do not independently review unrelated areas.
|
||||
|
||||
## Area-Specific Security Guidance
|
||||
|
||||
**Protocol State Machine and Event-Driven Lifecycle Bugs:**
|
||||
- Review transitions between listening, accepted, connecting, resolving, TLS handshaking, HTTP, WebSocket, MQTT, draining, closing, and closed states.
|
||||
- Check whether malformed input can cause protocol handlers to process data in the wrong state, process stale data after close, or invoke callbacks with invalid event data.
|
||||
- Look for use-after-free or stale pointer use when callbacks call `mg_close_conn`, mark a connection closing, mutate iobufs, change protocol handlers, or initiate TLS/WebSocket/MQTT transitions.
|
||||
- Verify that partial reads/writes, backpressure, `is_full`, draining, TLS pending states, and send-buffer mutations cannot cause duplicated sends, skipped validation, or parser confusion.
|
||||
- Review timer and wakeup handling for stale user data pointers, cross-thread queue misuse, and callbacks firing after associated connections/state have been freed.
|
||||
- Only report concurrency or race issues when a concrete event ordering can trigger memory corruption, unauthorized action, or reliable device/process crash.
|
||||
@@ -0,0 +1,26 @@
|
||||
# Security Scan Area: net_builtin
|
||||
|
||||
## Target
|
||||
|
||||
Area: net_builtin
|
||||
|
||||
This area covers the built-in TCP/IP stack and its selected L2 implementations.
|
||||
|
||||
Primary files:
|
||||
- `src/l2_*.c`
|
||||
- `src/net_builtin.c`
|
||||
|
||||
Perform a focused security review centered on these files and this security surface.
|
||||
|
||||
Supporting code outside these files may be inspected when necessary to establish reachability, data flow, state, validation, mitigation, or impact, but do not independently review unrelated areas.
|
||||
|
||||
## Area-Specific Security Guidance
|
||||
|
||||
**Built-In TCP/IP Stack, Packet Parsing, and Embedded Network Drivers:**
|
||||
- Review Ethernet, ARP, IP, IPv6, ICMP, UDP, TCP, DHCP, SNTP, and driver receive/transmit paths for packet-length validation before reading protocol headers.
|
||||
- Check IP/TCP/UDP header length fields, options length, fragmentation/reassembly behavior, checksum handling, and payload offset calculations for underflow, overflow, or out-of-bounds access.
|
||||
- Look for malformed packets that can corrupt descriptor rings, RX/TX buffers, queue state, ARP tables, connection state, or timers.
|
||||
- Review interrupt handlers and bare-metal driver code for bounded processing loops. Flag IRQ paths where attacker-controlled traffic can cause livelock, starvation, descriptor ownership loss, or repeated processing of the same malformed frame.
|
||||
- Check DMA descriptor ownership transitions, memory barriers, cache coherency handling, and buffer length fields for race-like bugs that can cause memory corruption or stale packet reuse.
|
||||
- Review platform-specific drivers such as STM32, NXP, TI, Microchip, Renesas, Infineon, Wiznet, Cypress WiFi, cellular, and other built-in stack integrations for inconsistent bounds checks or endian conversions.
|
||||
- Treat a remotely reachable malformed Ethernet/IP/TCP/UDP packet that crashes, wedges, or corrupts an embedded target as reportable.
|
||||
@@ -0,0 +1,38 @@
|
||||
# Security Scan Area: protocols
|
||||
|
||||
## Target
|
||||
|
||||
Area: protocols
|
||||
|
||||
This area covers the smaller externally controlled protocol parsers and state machines other than HTTP, WebSocket, and TLS.
|
||||
|
||||
Primary files:
|
||||
- `src/modbus.c`
|
||||
- `src/rpc.c`
|
||||
- `src/sntp.c`
|
||||
- `src/mqtt.c`
|
||||
- `src/dns.c`
|
||||
|
||||
Perform a focused security review centered on these files and this security surface.
|
||||
|
||||
Supporting code outside these files may be inspected when necessary to establish reachability, data flow, state, validation, mitigation, or impact, but do not independently review unrelated areas.
|
||||
|
||||
## Area-Specific Security Guidance
|
||||
|
||||
**MQTT Parser and Broker/Client State Machine Vulnerabilities:**
|
||||
- Review MQTT fixed header parsing, remaining-length decoding, variable-length integer loops, packet identifier handling, QoS transitions, topic extraction, property parsing, and MQTT 3.x vs MQTT 5 differences.
|
||||
- Look for malformed MQTT packets that can trigger out-of-bounds reads/writes, stack buffer overflow, heap corruption, assertion/crash, or parser desynchronization.
|
||||
- Specifically check SUBSCRIBE and UNSUBSCRIBE handling for unbounded numbers of topics, malformed topic length fields, missing QoS bytes, invalid QoS values, and writes to fixed-size response arrays.
|
||||
- Verify that PUBLISH handling enforces topic length, packet length, QoS rules, retained flag handling, packet identifier requirements, and message bounds before accessing fields.
|
||||
- Check broker examples and protocol handlers for authorization bypass, cross-topic data exposure, wildcard topic mishandling, `$SYS` or reserved topic confusion, and unintended publish/subscribe access.
|
||||
- Review MQTT reconnect/resubscribe logic for stale connection state, packet identifier reuse bugs, and memory lifetime problems after close/reconnect.
|
||||
- Treat unauthenticated single-packet broker crash, client crash from malicious broker response, or memory corruption during MQTT parsing as reportable.
|
||||
|
||||
**DNS and mDNS Parsing and Name Resolution:**
|
||||
- Review DNS and mDNS message parsing for label length validation, compression pointer loops, pointer bounds, recursive expansion limits, integer overflow, malformed resource records, and out-of-bounds reads.
|
||||
- Check that DNS answers are matched to outstanding requests by transaction ID, question name/type/class, and source expectations where applicable.
|
||||
- Look for cache poisoning, response spoofing, or name confusion if DNS response validation is weak in client or resolver code.
|
||||
- Verify that DNS failures, timeouts, and retries cannot leave dangling active request state or corrupt connection state.
|
||||
|
||||
**Modbus, RPC, and SNTP:**
|
||||
- Review externally controlled lengths, framing, message parsing, and protocol state for malformed peer input that can cause parser desynchronization, state corruption, or a remotely triggerable crash or wedge.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Security Scan Area: tls
|
||||
|
||||
## Target
|
||||
|
||||
Area: tls
|
||||
|
||||
This area covers the complete Mongoose TLS implementation represented by the primary files.
|
||||
|
||||
Primary files:
|
||||
- `src/tls_aes128.c`
|
||||
- `src/tls_builtin.c`
|
||||
- `src/tls_chacha20.c`
|
||||
- `src/tls_dummy.c`
|
||||
- `src/tls_mbed.c`
|
||||
- `src/tls_openssl.c`
|
||||
- `src/tls_rsa.c`
|
||||
- `src/tls_uecc.c`
|
||||
- `src/tls_x25519.c`
|
||||
|
||||
Perform a focused security review centered on these files and this security surface.
|
||||
|
||||
Supporting code outside these files may be inspected when necessary to establish reachability, data flow, state, validation, mitigation, or impact, but do not independently review unrelated areas.
|
||||
|
||||
Connection, core, network, and helper code may be inspected when needed to understand the complete TLS execution path.
|
||||
|
||||
## Area-Specific Security Guidance
|
||||
|
||||
### Mandatory High-Risk Coverage: Built-In TLS
|
||||
|
||||
The built-in TLS implementation (`MG_TLS_BUILTIN`) is a mandatory high-risk review target. Perform a substantial security analysis of all security-relevant built-in TLS code, including parsing, cryptographic processing, authentication and certificate validation, length and buffer handling, protocol state, cross-call behavior, and failure paths.
|
||||
|
||||
Trace attacker-controlled TLS peer input through normal client and server execution, including traffic received before peer authentication is complete. Report any credible memory-safety, authentication, confidentiality, integrity, state-corruption, or remotely triggerable availability vulnerability.
|
||||
|
||||
**TLS, Certificate, Hostname Verification, and Cryptographic Validation:**
|
||||
- Review all TLS backends, including built-in TLS, mbedTLS, OpenSSL, WolfSSL, and custom TLS integration, for equivalent security behavior where possible.
|
||||
- Flag certificate verification bypasses, accidental `skip_verification` use in security-sensitive examples or defaults, missing hostname verification when `name`/SNI is available, or inconsistent validation across TLS backends.
|
||||
- For hostname verification, check wildcard handling carefully. A wildcard certificate identity must not match multiple DNS labels. For example, `*.example.com` must not match `a.b.example.com`.
|
||||
- Verify that wildcard matching is applied only to certificate presented identifiers, not to arbitrary reference identifiers or general DNS glob matching.
|
||||
- Review `mg_match` or other glob/matching helpers if used for certificate identity checks, authorization checks, filesystem paths, routing, or topic matching. Flag cases where glob semantics are broader than the security policy requires.
|
||||
- Check certificate parsing for DER/PEM boundary errors, length overflows, malformed ASN.1, extension parsing mistakes, name constraints, SAN vs CN precedence, embedded NUL, and invalid string type handling.
|
||||
- Review TLS record parsing, handshake transcript handling, key schedule, random generation, ECC/X25519 operations, AES-GCM nonce/tag handling, and error handling for memory safety and authentication failures.
|
||||
- Flag any behavior that silently falls back from verified TLS to unverified TLS or plaintext.
|
||||
- Check that TLS receive/send error paths cannot corrupt connection state, reuse freed buffers, or continue processing unauthenticated plaintext as encrypted data.
|
||||
@@ -0,0 +1,62 @@
|
||||
# Security Scan Area: web_http_auth
|
||||
|
||||
## Target
|
||||
|
||||
Area: web_http_auth
|
||||
|
||||
This area covers HTTP parsing and framing, HTTP-facing filesystem behavior, SSI, WebSocket, authentication/token/dashboard code, and HTTP-based OTA behavior.
|
||||
|
||||
Primary files:
|
||||
- `src/http.c`
|
||||
- `src/ssi.c`
|
||||
- `src/ws.c`
|
||||
- `src/jwt.c`
|
||||
- `src/dash.c`
|
||||
- `src/ota.c`
|
||||
|
||||
Perform a focused security review centered on these files and this security surface.
|
||||
|
||||
Supporting code outside these files may be inspected when necessary to establish reachability, data flow, state, validation, mitigation, or impact, but do not independently review unrelated areas.
|
||||
|
||||
For OTA behavior, follow operations into TLS, flash, filesystem, JSON, URL, or other support code when necessary, while keeping the review centered on the `web_http_auth` surface.
|
||||
|
||||
## Area-Specific Security Guidance
|
||||
|
||||
**HTTP Parser, Request Smuggling, and Message Framing:**
|
||||
- Verify that HTTP requests or responses containing both `Content-Length` and `Transfer-Encoding` are rejected or handled in a way that cannot cause front-end/back-end desynchronization. Treat CL+TE coexistence as security-relevant request smuggling risk.
|
||||
- Verify that duplicate `Content-Length`, duplicate `Transfer-Encoding`, conflicting transfer codings, malformed chunk sizes, chunk extensions, premature EOF, and body length mismatches cannot cause inconsistent body parsing.
|
||||
- Check whether HTTP/1.0, HTTP/1.1, and malformed protocol versions alter CL/TE handling unsafely. A message with both `Content-Length` and `Transfer-Encoding` should not be accepted merely because of version differences.
|
||||
- Look for parsing paths where headers are normalized differently from later lookup paths, including case folding, whitespace around colon, obs-fold/line folding, embedded NUL, duplicate headers, or partial header names.
|
||||
- Review URL decoding, query parsing, multipart parsing, upload handling, range handling, and chunked responses for bounds mistakes, truncation, or inconsistent decoded-vs-raw path decisions.
|
||||
- Check static file serving and SSI handling for path traversal through percent-encoding, double decoding, backslashes on Windows, mixed separators, dot-dot segments, absolute paths, drive letters, symlinks, embedded NUL, or alias/root_dir confusion.
|
||||
- Review HTTP authentication helper paths for parsing ambiguities in Basic auth, header extraction, credential truncation, empty username/password acceptance, or incorrect comparison behavior.
|
||||
- Check that HTTP upgrade to WebSocket validates method, headers, key, version, and connection semantics consistently before switching protocol state.
|
||||
|
||||
**WebSocket Framing and Upgrade Vulnerabilities:**
|
||||
- Review WebSocket frame parsing for extended payload length handling, 16-bit/64-bit length conversion, masking rules, fragmentation, continuation frames, control-frame length limits, close/ping/pong handling, and compression-related assumptions if present.
|
||||
- Check that client-to-server frames require masking and that malformed mask/payload boundaries cannot read or write out of bounds.
|
||||
- Look for state-machine confusion after HTTP upgrade, especially where partial frames, fragmented messages, or mixed HTTP/WebSocket bytes can cause parser desynchronization.
|
||||
- Check whether large or malformed frame lengths can cause integer overflow, memory corruption, uncontrolled allocation, connection lockup, or single-connection/device crash.
|
||||
- Verify that WebSocket message APIs preserve attacker-controlled binary data length correctly and do not pass non-null-terminated payloads to C-string functions.
|
||||
|
||||
**HTTP-Facing Filesystem Serving, Uploads, and SSI:**
|
||||
- Review `mg_http_serve_dir`, `mg_http_serve_file`, upload APIs, and SSI expansion for traversal, unauthorized file read/write, overwrite, truncation, or unexpected executable/include behavior.
|
||||
- Look for inconsistent handling of decoded and undecoded paths, double decoding, query string leakage into path, trailing slash confusion, NUL byte truncation, and case sensitivity differences.
|
||||
- Review multipart upload parsing for boundary confusion, filename traversal, field length overflow, partial-write behavior, and max-size enforcement.
|
||||
- Check SSI include handling for directory escape, recursive include loops, unintended disclosure of local files, and parsing of attacker-controlled SSI directives.
|
||||
- Verify that range requests and static response headers cannot cause out-of-bounds reads or disclose memory.
|
||||
|
||||
**OTA/Firmware Update and Device Dashboard Security:**
|
||||
- Review firmware update endpoints and examples for missing authentication, authorization bypass, path confusion, arbitrary write, unsafe flash offset/length handling, and failure to verify firmware authenticity where the code claims secure update behavior.
|
||||
- Check update chunk parsing for integer overflow, flash boundary crossing, rollback/downgrade exposure, incomplete image bootability, and crash/power-loss unsafe state transitions.
|
||||
- Flag any code path where unauthenticated network input can write firmware, configuration, filesystem contents, flash pages, bootloader state, or device identity material.
|
||||
- Review device dashboard examples for security-sensitive default routes, credentials, upload handlers, debug endpoints, config mutation endpoints, and CORS/header behavior when they are likely to be copied into production.
|
||||
- Do not report ordinary insecure demo behavior unless it creates a realistic copy-paste production vulnerability or affects library code.
|
||||
|
||||
**Authentication, Authorization, and Access-Control Patterns in Mongoose Integrations:**
|
||||
- Review examples and helper APIs that implement HTTP auth, cookies, sessions, tokens, device dashboards, REST APIs, upload endpoints, and firmware update endpoints.
|
||||
- Flag authentication bypasses caused by prefix route matching, glob matching, decoded-vs-raw URI confusion, case normalization mistakes, missing boundary checks, or default-open sensitive endpoints.
|
||||
- Check for authorization decisions made in client-side JavaScript only. Client-side checks are not security boundaries.
|
||||
- Review CORS and origin checks only when they protect credentialed sensitive operations and the exploit path is concrete.
|
||||
- Look for credential comparison bugs, truncation of usernames/passwords, accepting empty credentials, parsing only part of an Authorization header, or treating malformed credentials as anonymous-but-authorized.
|
||||
- Flag sensitive data exposure when secrets, credentials, tokens, private keys, firmware signing material, PII, or device identity values can be read by unauthorized remote clients or logged from attacker-triggered paths.
|
||||
Reference in new issue
Block a user