docs(review): 2026-12-02 full code review (10 slices, ~150 findings) + remediation plan

Tracked as #971-#1002.
This commit is contained in:
Joseph Doherty
2026-12-02 16:06:45 -05:00
parent 440b182f33
commit 65fd71de7a
12 changed files with 4267 additions and 0 deletions
@@ -0,0 +1,217 @@
# 2026-12-02 review remediation plan
Source: `docs/reviews/2026-12-02/` (00-SUMMARY + 10 slice reports), master @ `708a4889c`. ~150 findings: 2 Critical, 19 High,
62 Medium, 67 Low. Finding IDs (R-, U-, C-, A-, H-, K-, G-, M-, P-, S-) refer to the slice reports, which carry the
file:line, failure scenario, suggested fix and test for each.
## Ground rules
- **Status lives in Gitea, not here.** File one issue per workstream below (labels `type:review-finding` + priority;
`blocked`/`cross-repo` where noted) and reference `#N` from this plan. Don't tick boxes in this file.
- **Fix the pattern, not the instance.** Each workstream names the shared seam; fix it there and then sweep the listed instances.
- **Every fix lands with the test named in its finding.** For absence bugs (something *not* happening), the test needs a positive
control (`project_test_absence_positive_control`).
- **Re-verify before fixing.** Most findings come from reading the code. Start each workstream by reproducing its finding
in a failing test; a finding that doesn't reproduce gets closed as not-a-defect, with the evidence.
- **Live gate per wave** on docker-dev (login disabled, so drive `/run` yourself). Hardware/VM gates are listed per item.
- Work in parallel worktrees per workstream (the #938–#968 batch pattern), with a review round per merge. Every past review
round caught real defects that green tests missed.
## Issue map (Gitea, filed 2026-12-02)
| Issue | Scope | Pri |
|---|---|---|
| #971 | W0.1 sandbox (K-1) | p0 |
| #972 | W0.2 ACL revalidation regression (U-1) | p0 |
| #973 | W0.3 fleet-diagnostics SSRF (A-1) | p1 |
| #974 | W0.4 Sql read-only guard (S-7) | p1 |
| #975 | W0.5 AdminUI role freshness (A-2) | p2 |
| #976 | W1.1 alarm S&F / historian transient (G-16≡K-2, G-8, G-7) | p1 |
| #977 | W1.3 deploy/apply bookkeeping (R-1, U-2, U-3, U-9, R-4, R-15, R-20, H-4) | p1 |
| #978 | W1.4 name authority + script gate (C-1≡R-5, C-4, C-7, C-2) | p1 |
| #979 | W1.5 stale/rejected Good (U-4, R-6, G-4) | p2 |
| #980 | W1.7 host liveness (H-1, H-2, H-5) | p1 |
| #981 | Modbus (S-1, S-2, S-8) | p1 |
| #982 | TwinCAT (P-1, P-3, P-4, P-12, P-19, P-22, P-25) | p1 |
| #983 | AbCip (P-2, P-13, P-16, P-17, P-22, P-23, P-24) | p1 |
| #984 | AbLegacy (P-5, P-14, P-15, P-18, P-23) | p1 |
| #985 | FOCAS (P-6…P-11, P-20, P-21, P-25) | p1 |
| #986 | S7 (S-5) | p2 |
| #987 | Sql driver (S-6, S-10) | p2 |
| #988 | MQTT/Sparkplug (M-1, M-2, M-3, M-6, M-11…M-15) | p2 |
| #989 | MTConnect (M-4, M-5, M-7…M-10) | p2 |
| #990 | Heidenhain (M-16…M-19) | p3 |
| #991 | Galaxy (G-1…G-6, G-19 — cross-repo mxaccessgw) | p2 |
| #992 | OpcUaClient (G-10…G-15) | p2 |
| #993 | Historian backends (G-9, G-17, G-18) | p3 |
| #994 | W3 gRPC data / projected scaling (R-2, R-3, R-7…R-10, R-12, R-13, R-21…R-24, U-10…U-13) | p1 |
| #995 | W4 deploy-path perf (K-3, R-11, R-14, U-5, R-17, R-19, S-9) | p2 |
| #996 | W4 ConfigDb/page/history perf (C-6, C-11≈A-5, A-8, H-3, H-6, U-6) | p2 |
| #997 | AdminUI correctness (A-3, A-4, A-6, A-7, A-9) | p2 |
| #998 | Configuration gaps (C-3, C-5, C-8, C-9, C-10) | p2 |
| #999 | Core scripting/alarms/resilience (K-4…K-11) | p2 |
| #1000 | Client.Shared (S-3, S-4, S-12) | p3 |
| #1001 | Analyzer OTOPCUA0001 (S-11) | p2 |
| #1002 | Runtime/OpcUaServer residual (R-16, R-18, R-25, U-7, U-8) | p3 |
---
## Wave 0 — Security + Critical (do first, P0/P1)
### W0.1 Script sandbox (K-1) — P0
- Stopgap now (option 2 in K-1): deny `Delegate.CreateDelegate`/`DynamicInvoke`/`Method`, `System.Linq.Expressions`, `System.Xml*`,
`System.Formats`, `System.Timers`, `System.ComponentModel`, `System.Security`, `System.Data`, `System.Resources`,
`System.Runtime.Serialization`, `ParallelEnumerable`, `Serilog.Log`/`LoggerConfiguration`, and the reflection-returning
`System.Type` members. File: `Core.Scripting/ForbiddenTypeAnalyzer.cs:43-152`.
- Real fix: invert to an **allow-list** (option 1) and narrow `ScriptSandbox.EnumerateBclAssemblyPaths` (option 3).
The editor diagnostics share the same analyzer, so Monaco ⇔ publish parity is kept automatically. Re-run the analyzer
over every stored script in the docker-dev ConfigDb so legitimate scripts aren't broken.
- Make the host write the PE cache, not the worker (option 4).
- Document in `docs/VirtualTags.md`/`docs/security.md` that InProcess scripting = Designer code execution as the service until the allow-list ships.
- Test: theory over the 8 bypass snippets in `ForbiddenTypeAnalyzerTests`, plus an allow-list regression over the shipped sample scripts.
### W0.2 ACL revalidation regression (U-1) — P0
- `IsSubscriptionStillPermitted` → route through `Permits(identity, CreateMonitoredItems, nodeId)` (it carries the flag-off
bypass); null-guard `_authorizer`; fix the timer remark. Files: `OtOpcUaNodeManager.cs:848,8741,8876-8975`.
- Revisit `SecurityFilteringActive`'s `NamespaceIndexes.Count >= 4` term (always true). Decide whether it should exist at all.
- Test: flag-off, anonymous subscription survives N revalidation passes + a deploy (with a positive control: flag-on denies it).
- Live gate: docker-dev, Client.CLI anonymous `subscribe` held for 3 min across a deploy.
### W0.3 AdminUI fleet-diagnostics SSRF (A-1) — P1
- Resolve `?node=` / the typed box against Up driver members ∪ enabled `ClusterNode` `Host:AkkaPort`; reject otherwise.
Add a defence-in-depth regex in `FleetDiagnosticsClient`. Consider raising the page policy to `DriverOperator`.
- Also audit the cluster HOCON for Akka `trusted-selection-paths` / untrusted-mode (cross-slice; H slice).
### W0.4 SQL read-only guard (S-7) — P1
- `SqlNamedQuery.cs:138-224`: make the guard dialect-aware (MySQL backslash escapes, Postgres `$tag$` quoting) **and**
execute read-only statements in a read-only transaction / read-only connection where the provider supports it,
so the guard is no longer the only line of defence.
- Gate: run the bypass strings against the Postgres + MySQL fixtures on `10.100.0.35`.
### W0.5 AdminUI role freshness (A-2) — P2
- Re-validate role claims on a timer (cookie `OnValidatePrincipal` with a short refresh window), and have open circuits
re-check through `RevalidatingServerAuthenticationStateProvider`.
---
## Wave 1 — Data loss & silent wrong data (P1)
### W1.1 Transient ≠ permanent in alarm history (G-16 ≡ K-2, G-8, G-7)
- `LocalDbStoreAndForwardSink.cs:28-35`: `RetryPlease` must not consume `MaxAttempts` — only `PermanentFail` (or a
poison-payload classification) counts; outage retries back off capped and never dead-letter.
- `GatewayAlarmHistorianWriter.cs:286-299`: `Cancelled`/`Unknown`/`Unavailable`/`DeadlineExceeded` and non-RPC transport
exceptions → `RetryPlease`.
- `FasterLogHistorizationOutbox.cs:151-155` (G-7): truncate only up to the last *indexed* address.
- Test: a 10 min simulated outage loses 0 events; reconnect drains everything in order.
- Gate: the historian live-gate recipe in `.claude/rules/historian.md` (SqlServer + QuestDb backends locally; the AVEVA gateway leg is user-gated).
### W1.2 Wire desync / stale-offset reads reported Good (S-1, P-1, P-10)
- **S-1** Modbus RTU-over-TCP: tear the socket down on any exit from `SendOnceAsync` after the request was written
(cancel included). Test: cancel mid-transaction, then the next read gets its own reply.
- **P-10** FOCAS: close the session on non-transient protocol errors and match replies to requests.
- **P-1** TwinCAT: watch the ADS symbol-version / `AdsState` change notification; on change, invalidate the symbol cache,
re-resolve handles and re-register notifications; mark values `BadConfigurationError`/`Uncertain` until re-resolved.
Gate: TCBSD VM (`10.100.0.128`), online change + full download. Note in the issue that the finding relies partly on decompiled Beckhoff cache behaviour.
### W1.3 Deploy/apply bookkeeping (R-1, U-2, U-3, U-9, R-4, R-15, R-20, H-4)
- **R-1** `DriverHostActor.Bootstrap`: restore from the newest **Applied** artifact, not the newest row. Test + docker-dev
gate: a failed deploy followed by a node restart serves the last good address space.
- **U-2/U-3/U-9** planner: add scripted-alarm `Enabled`/`AlarmType`/`Severity`/`Name` and Line→Area parentage to the diff
(Line re-parent ⇒ rebuild, or a surgical move). Remove the VirtualTag sub-folder with the variable. This is the "omitting a field
silently reopens staleness" class: add a test that reflects over the record fields so a new field can't be skipped.
- **R-4** keep the degraded flag until a full re-ensure succeeds; **R-15** advance the revision after the last throwing step;
**R-20** persist/restore `_lastApplied` across `OpcUaPublishActor` restart (or force a rebuild on restart).
- **H-4** `HandleDispatch` must close (fail/supersede) the prior in-flight deployment row.
### W1.4 One name authority (C-1 ≡ R-5, C-4, C-7, C-2)
- Expose a single `V3NodeIds.ValidateSegment(string)` (the exact rule `Uns(...)` enforces) and call it from the VirtualTag
modal, the `DisplayNameOverride` editor, CSV import **and** `DraftValidator`. Fix `UnsSegment` to use `\z` and not `$` (C-7).
- **R-5** defensive: `VirtualTagHostActor` skips and reports an invalid tag instead of crashing on every apply.
- **C-2** add a script-existence gate rule for VirtualTags + ScriptedAlarms, and block deleting a script that's in use
(usage check in the service; an FK if the model allows).
- Gate: docker-dev, an author `a/b` VirtualTag is rejected in the modal *and* by publish.
### W1.5 Initial/stale publish correctness (S-2, U-4, R-6, G-4)
- **S-2** clear `_lastPublishedByRef` for refs on (re)subscribe. **U-4** revert to the last *confirmed* value, tracking per-write
generations. **R-6** dependents of a removed input go `BadWaitingForInitialData`/`Bad`. **G-4** a dropped pump event triggers a
re-read of that tag (or marks it Uncertain).
### W1.6 Driver data-shape bugs (P-5, P-13, P-14, P-15, P-9, S-8)
- **P-5** AbLegacy: reject a `Long` on a MicroLogix per-tag (BadConfigurationError) + a deploy-gate rule, without faulting the driver.
- **P-13** AbCip BOOL array: element count = DWORDs (gate: `ab_server`). **P-14/P-15** AbLegacy bit arrays: size in words;
a `Bit` write without `/n` is rejected or RMWs bit 0 (decide; document).
- **P-9** FOCAS keep the slot index. **S-8** DL205: an invalid octal is an error, not a fallback.
### W1.7 Host liveness (H-1, H-2, H-5)
- **H-1** a node that is downed or leaves the cluster exits non-zero so SCM recovery fires. Gate: `windev` (not the wonder boxes).
- **H-2** `AuditWriterActor`: clear the buffer only after save succeeds, with a bounded retry buffer. **H-5** an HTTPS binding fails validation and stops the node from booting.
---
## Wave 2 — Health contract & device isolation (P1/P2)
### W2.1 Refusal vs comms-fault classification
Add the shared helper (or extend the existing status mapping) and sweep: P-6 FOCAS fixed-tree, P-12 TwinCAT
`TwinCATStatusMapper.cs:84` default, S-5 S7 bad write values → `BadOutOfRange`/`BadTypeMismatch`, G-9 Gateway read refusals,
G-14 OpcUaClient post-dispatch write → `BadTimeout`, R-8 projected `QueryAsync` per-call faults, R-10 publisher capacity refusal,
P-7 FOCAS transient bootstrap latch, P-21 `CoalesceRejected` latch. Test pattern: a refusal leaves health Healthy and
the watchdog quiet; a real outage degrades.
### W2.2 Outages that never degrade
M-2 MQTT: subscribe per filter (or validate filters at authoring and at the gate) and degrade on SUBACK failure; M-14 browse honours
CONNACK/SUBACK; G-19 mxaccessgw HTTP/2 keep-alive + stream idle timeout (**cross-repo** `mxaccessgw`); M-6 Sparkplug primary-host
re-claim after reconnect; M-1 the rebirth give-up counter is not reset by the NBIRTH it provoked; M-3 derive a unique
primary-host client id.
### W2.3 One dead device stalls the rest
P-2 AbCip warm-handle backoff + per-device batching; P-3 TwinCAT per-device parallel reads with fail-fast; P-4 skip the registration
replay while the device is offline; P-11/P-8 FOCAS: check backoff before the gate, bound the close handshake. Gates: TCBSD VM,
FOCAS sim, AbCip `ab_server` (multi-device with one blackholed).
---
## Wave 3 — gRPC data / projected path scaling (P2)
Owner seam: `Runtime/DataConnections/*` + the projected half of `OtOpcUaNodeManager`. Keep #969 in the same issue family.
- **R-2** batch cohort opens into one stream command (or pace them under the origin's 128/s limit).
- **R-3** scan partition changes for the session's own sources (an index per source), not the first 32 global changes.
- **R-7** a full channel must not tear down sibling demands (backpressure instead). **R-9** invalidate per-source, and treat lock contention as not an invalidation.
- **R-12** authorize once per frame (memoised per session epoch). **R-13** copy-on-write handle tables.
- **U-10** index live items by node for `TryPublish`. **U-12** O(1) eviction (LRU). **U-11** tombstone the monitored node on anchor removal.
- **R-21, R-22, R-23, U-13** small fixes in the same files.
- Perf test: a 10k-item cohort open plus a 1k values/s publish, with before/after numbers recorded in the issue.
## Wave 4 — Deploy-path & page performance (P2)
- **K-3** cache compiled predicates by source hash and compile outside the engine gate (swap under the gate). Measure before and after on a deploy with 500 alarms.
- **R-11** re-subscribe only drivers whose desired set changed. **R-14** parse the artifact data projection once per apply, off the pinned thread.
- **U-5** index stood-down items by node. **U-6** add a server page cap for `HistoryReadEvents` (the same pattern as the raw cap from the October review).
- **C-6** project `Deployment` without `ArtifactBlob` in the health probe and readiness check. **C-11 ≈ A-5** add a scoped snapshot loader for the data-connections page.
- **H-6** run EF calls off the coordinator thread (PipeTo). **H-3** run AdminOps DB I/O off the mailbox, and audit before dispatch (or make the reply idempotent).
- **R-17, R-19, S-9** coalesce the VirtualTag/Calculation evaluation backlogs (latest-value-wins per tag), with a bounded queue.
## Wave 5 — Remaining Medium bugs (P2/P3)
Lifecycle/leaks: M-5 MTConnect subscription release, A-6 reaper drain, R-16 `StopChild` comms-latch + timer, G-11 OpcUaClient
unsubscribe ordering, M-13 MQTT handle cleanup.
Correctness: A-3 duplicate sibling names (pre-check + `DbUpdateException` handling), A-4 Galaxy ack password blanking, C-3 ZTag/SAPID
reservations (write `ExternalIdReservation` or remove the UI claim), C-5 historian tagname collision rule, K-4 shelve-expiry event,
K-5 frame cap split, K-6 resilience timeout visible to breaker, S-3/S-4 Client.Shared failover retry + map reset, S-6 Sql key
comparison by provider semantics, M-4 MTConnect intra-chunk fault, G-1 Galaxy security map filled at init, G-10 OpcUaClient recovery index,
P-16 AbCip log throttling, P-17 ALMD `OperAck` (hardware-gated, #592), P-18/P-19 coalescing + per-poll cost, P-20 FOCAS truncation.
## Wave 6 — Low items
Batch by slice: one issue per slice report covering its remaining Low findings (R-18, R-24, R-25, C-7…C-10, A-7…A-9, K-7…K-11,
G-2, G-3, G-5, G-6, G-12, G-13, G-15, G-17, G-18, M-7…M-12, M-15…M-19, P-22…P-25, S-10…S-12). S-11 (analyzer coverage) should go
earlier: extending OTOPCUA0001 will flag `DriverInstanceActor.cs:2251` and may surface more instances.
---
## Sequencing & parallelism
| Order | Workstreams | Can run in parallel | Gate |
|---|---|---|---|
| 1 | W0.1, W0.2, W0.3, W0.4 | yes (disjoint files) | docker-dev + Sql fixtures |
| 2 | W1.1–W1.7, W0.5 | yes; W1.3 and W1.4 both touch `DraftValidator` / the planner, so split by file or run them sequentially | docker-dev, historian, TCBSD, windev |
| 3 | W2.1–W2.3 | per driver | fixtures + TCBSD + `ab_server` |
| 4 | W3, W4 | W3 is one owner (shared files) | perf numbers in issue |
| 5 | W5, W6 | per slice | unit + spot live |
## Blocked / external
- G-19 needs an `mxaccessgw` client change (**cross-repo**). Update the umbrella index row only if the wire contract changes.
- P-17 and P-13 need bench hardware or `ab_server` (#592). H-1 needs Windows (`windev` is fine; the wonder boxes are on hold, so no psbridge/winrm).
- Deploying any of this to the wonder boxes is blocked by the 2026-09-11 hold.