google / cel-go

Fast, portable, non-Turing complete expression evaluation with gradual typing (Go)
https://cel.dev
Apache License 2.0
2.3k stars 224 forks source link

Support runtime options to limit and disable comprehension macros #1050

Open sergiitk opened 1 month ago

sergiitk commented 1 month ago

Feature request checklist

Change To make CEL environment setup consistent across CEL implementations, I propose to add a runtime option equivalent to CEL-cpp InterpreterOptions.enable_comprehension to CEL-Go and CEL-Java (corresponding ticket https://github.com/google/cel-java/issues/484).

In Java, runtime CEL comprehensions can be limited using comprehensionMaxIterations(int value) runtime option. Setting value to 0 disables the comprehension macros. If the limit is reached, program evaluation throws CelEvaluationException with CelErrorCode.ITERATION_BUDGET_EXCEEDED.

There is no option equivalent to comprehensionMaxIterations() in CEL-Go . Similar to google/cel-java#484, the new Go option equivalent to cpp's enable_comprehension could use comprehensionMaxIterations(0) under-the-hood.

Example

// Actual option names up to the implementer.
prg, err := env.Program(ast, EvalOptions(OptDisableComprehension))

// Equivalent:
prg, err := env.Program(ast, ComprehensionMaxIterations(0))

Related Internal ref: go/grpc-cel-integration