fix(script-analysis): key the trust verdict cache on every verdict input (CMN-5, WP1 task 1.3)
TrustVerdictCache keyed on the code hash alone while the verdict also depends on the analysis reference set (and its degraded-fallback mode). The key is now (code SHA-256, degraded flag, base-reference fingerprint, extra-reference digest), length-prefixed. File-backed extra references are digested (path/size/mtime/kind/aliases/embed) so the Central UI run gate's calls are cached under their own key; an extra reference with no stable identity stays uncacheable. The old extras test passed a PortableExecutableReference[] positionally, which binds to the explicit-base overload, so it never exercised the extras path; the tests now use the named argument.
This commit is contained in:
@@ -223,7 +223,7 @@ All five call sites that previously maintained their own script trust enforcemen
|
||||
| **Central UI** `ScriptAnalysisService` | Semantic + full compile, lenient threading | Delegates forbidden-API verdict and sources editor-marker deny-list from `ScriptTrustPolicy`; retains Test-Run execution host |
|
||||
| **Transport** `BundleImporter.RunSemanticValidationAsync` / `DetectBlockersAsync` | No trust gate — a bundle's forbidden-API scripts imported clean, deferred to runtime (fifth write path) | Runs `ScriptTrustValidator.FindViolations` over every non-Skip template / shared / ApiMethod body, template script + alarm Expression-trigger bodies, **and instance alarm-override trigger expressions** at import review — hard error (apply) / Blocker row (preview) for all kinds |
|
||||
|
||||
**Trust verdicts are memoised (review 2026-10-21 04/P3).** `ScriptTrustValidator.FindViolations(code)` — the default-reference-set entry point every consumer above uses — caches its verdict process-wide by SHA-256 of the code (`TrustVerdictCache`: two generations of 1 024, cold-hit promotion, a throwing analysis is never stored; verdicts are returned as read-only collections and a hit returns the same instance). The verdict is a pure function of the code because the policy and `AnalysisReferences` are process-static. This removes the repeat full-framework semantic analysis the Transport importer used to pay on preview **and** again on apply (and on every wizard re-entry to preview) with no change at its call sites. A call that passes non-empty `extraReferences` (Central UI's run gate) bypasses the cache, since extra references can change resolution; the explicit-`baseReferences` overload is never cached.
|
||||
**Trust verdicts are memoised (review 2026-10-21 04/P3).** `ScriptTrustValidator.FindViolations(code)` — the default-reference-set entry point every consumer above uses — caches its verdict process-wide (`TrustVerdictCache`: two generations of 1 024, cold-hit promotion, a throwing analysis is never stored; verdicts are returned as read-only collections and a hit returns the same instance). Since code review 2026-12-02 CMN-5 the key is every input the verdict depends on — the SHA-256 of the code, a fingerprint of `AnalysisReferences`, the `AnalysisReferencesDegraded` flag and a digest of the `extraReferences` — not the code alone; the base set and the flag are process-static today, but carrying them makes the memo self-invalidating if the resolution surface ever varies. This removes the repeat full-framework semantic analysis the Transport importer used to pay on preview **and** again on apply (and on every wizard re-entry to preview) with no change at its call sites. A call that passes non-empty `extraReferences` (Central UI's run gate) is cached under its own key when every extra reference is file-backed (digest = path, size, last-write time, kind, aliases, embed-interop flag), so it is never served the no-extras verdict or vice versa; an extra reference with no stable identity (an in-memory image) makes the call uncacheable. The explicit-`baseReferences` overload is never cached. (Note: a positional `PortableExecutableReference[]` second argument binds to that explicit-base overload, not to `extraReferences` — use the named argument.)
|
||||
|
||||
The static enforcement is **defence-in-depth**, not a true runtime sandbox. The denied API list blocks disallowed APIs at compile time but does not establish an operating-system security boundary. Site-runtime consumers execute in-process. Central UI Test Run uses a bounded, killable worker process; that adds resource/lifetime containment, while the worker retains the same operating-system identity and permitted gateway access.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user