0002. Expressions can call only registered types
Status
Accepted. Recorded retroactively. Introduced in version 5.0.0.
Context and problem statement
Rule text comes from a store and is evaluated inside the host application. If an expression could call any method on any type, whoever can edit a rule could run arbitrary code in the application. A security issue of this kind was reported against System.Linq.Dynamic.Core, which the engine uses (see the 5.0.0 entry in the change log).
Decision drivers
- Rules must not be able to reach arbitrary framework APIs.
- Legitimate rules need helper methods and methods on their input types.
- The common case, calling methods on the inputs, should keep working without ceremony.
Considered options
- Allow only registered types: an explicit list in
ReSettings.CustomTypes, plus the input types, plus a small built-in set. - Allow every type that is loaded.
- Forbid all method calls in expressions.
Decision outcome
Only registered types are available for method calls and static members. CustomTypeProvider builds the set from CustomTypes, the types of the inputs (when AutoRegisterInputType is on), ExpressionUtils, Enumerable, and their base types and interfaces. Types marked [DynamicLinqType] are added when EnableAssemblyScanning is on. See the type security model.
Consequences
- Good: a rule can use only what the application chose to expose.
- Good: input types work automatically, so most existing rules kept working.
- Bad: this was a breaking change in 5.0.0, because rules that called other types had to be registered (see the upgrade guide).
- Bad:
EnableAssemblyScanningis on by default for compatibility, which adds assembly-scanning cost and includes every[DynamicLinqType]in loaded assemblies. Applications can turn it off for an explicit allow-list.