fix(scripting): block dangerous System types in the script sandbox (Core.Scripting-001)
ForbiddenTypeAnalyzer used only a namespace-prefix deny-list. System.Environment, System.AppDomain, System.GC and System.Activator live directly in the System namespace, which must stay allowed for primitives (Math, String, ...), so they were never caught — an operator-authored predicate could call System.Environment.Exit(0) and terminate the in-process OPC UA server. Add a type-granular deny-list (ForbiddenFullTypeNames) checked by fully-qualified type name after the namespace-prefix check; legitimate System types are unaffected. Regression tests assert scripts referencing Environment/AppDomain/GC/Activator are rejected at analysis time. Core.Scripting suite: 68/68 pass. Resolves code-review finding Core.Scripting-001 (Critical). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
| Review date | 2026-05-22 |
|
||||
| Commit reviewed | `76d35d1` |
|
||||
| Status | Reviewed |
|
||||
| Open findings | 11 |
|
||||
| Open findings | 10 |
|
||||
|
||||
## Checklist coverage
|
||||
|
||||
@@ -36,7 +36,7 @@ a category produced nothing rather than leaving it blank.
|
||||
| Severity | Critical |
|
||||
| Category | Security |
|
||||
| Location | `ForbiddenTypeAnalyzer.cs:45`, `ScriptSandbox.cs:54` |
|
||||
| Status | Open |
|
||||
| Status | Resolved |
|
||||
|
||||
**Description:** `System.Environment` lives in the allowed `System` namespace (it is in
|
||||
`System.Private.CoreLib`, which is allow-listed for primitives) and is not on the
|
||||
@@ -57,7 +57,14 @@ for types in allowed namespaces. Add an explicit forbidden-member deny-list to
|
||||
`GC.AddMemoryPressure`), and `System.Activator.CreateInstance` (a reflection-equivalent
|
||||
escape). Reject these in `CheckSymbol` by resolved method symbol, with a test for each.
|
||||
|
||||
**Resolution:** _(open)_
|
||||
**Resolution:** Resolved 2026-05-22 — added a type-granular `ForbiddenFullTypeNames`
|
||||
deny-list (`System.Environment`, `System.AppDomain`, `System.GC`, `System.Activator`) to
|
||||
`ForbiddenTypeAnalyzer`; `CheckSymbol` now rejects any resolved type symbol whose
|
||||
fully-qualified name matches, alongside the existing namespace-prefix check, so dangerous
|
||||
`System`-namespace process-control types are blocked at compile while legitimate `System`
|
||||
types (Math, String, …) stay usable. Regression tests added in `ScriptSandboxTests` for
|
||||
`Environment.Exit` / `Environment.FailFast` / `Environment.GetEnvironmentVariable` /
|
||||
`AppDomain` / `GC.Collect` / `Activator.CreateInstance`.
|
||||
|
||||
### Core.Scripting-002
|
||||
|
||||
|
||||
Reference in New Issue
Block a user