fix(script-analysis): inspect ?. member bindings and CreateDelegate in the trust gate (CMN-1, WP1 task 1.1)

The reflection-gateway check ran only in VisitMemberAccessExpression, so
recv?.GetMethod(...) (a MemberBindingExpression) was never inspected and
Delegate.CreateDelegate turned the MethodInfo into a callable delegate:
one character defeated the trust gate on all four call sites.

- HardeningWalker gains VisitMemberBindingExpression with the same check.
- CreateDelegate joins ReflectionGatewayMembers.
- Pass 1 also flags a gateway-named framework member reached as a bare
  identifier (using static System.Delegate / System.Type).

Tests: the review's probe script (compiles clean, now rejected, also on
the minimal fallback set), the ?. variant of every .-form rejection test,
every gateway member via ?., and legitimate ?. use stays clean.
This commit is contained in:
Joseph Doherty
2026-12-03 09:43:55 -05:00
parent f7e4f5b4ed
commit 29192eeb44
4 changed files with 228 additions and 3 deletions
@@ -111,6 +111,11 @@ public static class ScriptTrustPolicy
"DeclaredMembers",
"DeclaredConstructors",
"DynamicInvoke",
// Code review 2026-12-02 CMN-1: Delegate.CreateDelegate / MethodInfo.CreateDelegate
// turn a MethodInfo (obtainable from System.Type, which is not a forbidden scope)
// into a directly-callable delegate, so a forbidden method can be invoked without
// ever naming a System.Reflection member. No legitimate script use.
"CreateDelegate",
// DELIBERATELY EXCLUDED: "Invoke". The syntactic pass rejects a gateway
// member regardless of receiver, and delegate.Invoke() is a legitimate,
// common script pattern (Func<>/Action<> invocation). MethodInfo.Invoke