Repository navigation
fix: validate complete Modbus discovery responses - #4
Merged
Merged
Conversation
Correlate complete replies, bind basic-object pages to the fixed query, and reject reserved TCP exception codes. Preserve TCP-only evidence. AI-assisted implementation and independent review; 386 local tests passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Discovery previously treated any nonempty TCP reply as Modbus and kept only the first recv fragment. HTTP text, unrelated transactions, wrong units and truncated frames could receive a Modbus label. Both discovery paths now assemble a bounded response and validate its request association before classification. Standard reads reuse the existing validator; the fixed basic-device-ID query checks its response structure and bounded object list. Basic pages must satisfy the fixed object0 query and make progress; reserved exception codes are refused. Valid exceptions are labelled as protocol reachability, while an open TCP port retains its connection result if protocol verification fails.
Request bytes, configured TCP0, scan limits, 0.45-second response budgets and 260-byte caps remain. The ID query reports only the first page and sends no follow-up. This does not authenticate hardware, infer vendor models or change HTTP, storage or task behavior.
Validation: 111 new focused tests, with the original implementation failing 46 / passing 18 before correction; review regressions separately recorded 24 failures and 22 passes, then passed after the two discovered gaps were fixed; all 386 local tests now pass. Cases include bad headers/PDU lengths, exceptions, deterministic fragmentation at every split, partial-frame interruptions, register fallback and real loopback TCP. Configuration validation and 23 offline checks pass. A zero-package parser smoke also checks 10,000 seeded structured byte inputs; these are property assertions, not additional pytest cases. Broad coverage is reported separately in the local evidence, without a claim of comprehensive security coverage.
Implementation, tests, review and documentation are AI-assisted. Tests use Fake byte sockets or loopback; no field devices were contacted and no dependencies were installed. Protocol reference: Modbus Application Protocol V1.1b3 §6.21/§7 and the TCP MBAP guide.