This document describes the security model, threat boundaries, and security
recommendations for cel-cpp. It is intended to help developers understand what
security guarantees cel-cpp provides and how to safely parse, type-check, and
evaluate CEL expressions and configurations.
The structure and tiering of this threat model are modeled after the Protocol Buffers Security Policy.
If you believe you have discovered a security vulnerability in cel-cpp, please
report it via
Google's official vulnerability disclosure channel.
For reports that do not meet the criteria or bar for the Google Vulnerability Reward Program (VRP) but are still security-sensitive, you can privately report them by opening a draft GitHub Security Advisory.
If an issue relates to something listed under Outside of Threat Model (Best-Effort Hardened) below, please open a public GitHub issue instead.
- Apply and verify defensive limits:
cel-cppenforces default limits in the parser, type checker, and runtime, but several important protections require explicit caller configuration:- Parser (
cel::ParserOptions): Keep default limits enabled or lower them for untrusted input (max_recursion_depth = 32,expression_size_codepoint_limit = 100000,expression_node_limit = 100000,error_recovery_limit = 12,error_recovery_token_lookahead_limit = 512). - Type Checker (
cel::CheckerOptions): Keepmax_expression_node_count(default100000),max_error_issues(default20), andmax_type_decl_nesting(default13) bounded. If type declarations themselves are not fully trusted, lowermax_type_decl_nesting(for example, to3) to prevent compounding type nesting. - Runtime (
cel::RuntimeOptions):- Keep
comprehension_max_iterationsbounded (default10000;0disables the limit). - Set
regex_max_program_sizeto a non-zero value if untrusted expressions or inputs can supply regular expressions. By default,regex_max_program_sizeis0(unbounded). - Keep
enable_comprehension_list_appendandenable_comprehension_mutable_mapdisabled unless evaluating trusted, type-checked ASTs.
- Keep
- Canonical Extensions (
extensions/): Only enable the extensions and extension versions required by the application, and tighten extension-specific limits for untrusted expressions—for example, lowercel::extensions::ListsExtensionOptions::max_range_size(default1000000), boundcel::extensions::StringsExtensionOptions::max_precision(default1000), and setRuntimeOptions::regex_max_program_sizewhen enabling the regex extension. - AST Validators (
validator/): UseComprehensionNestingLimitValidator,BindNestingLimitValidator,AstDepthValidator, andRegexValidatorto bound expression complexity and prevent CPU/memory amplification before evaluation. - Input and environment bounds: Bound the size and nesting of values
passed in
cel::Activation(strings, bytes, lists, maps, and Protobuf messages).cel-cppdoes not enforce a global memory cap or runtime cost budget on string/list concatenation (+),cel.bindchaining, or comprehension output growth.
- Parser (
- Treat YAML configurations as code: Environment YAML
(
cel::EnvConfigFromYaml) and policy YAML (cel::YamlPolicyParser) should only be loaded from trusted or vetted sources, similarly to source code or.protoschemas. When loading environment YAML configurations shared withcel-goorcel-java, enablecel::EnvConfigFromYamlOptions::strict = trueso that unimplemented fields (such aslimits,validators,imports, andfeatures) fail closed instead of being silently ignored. - Only trust ASTs from trusted compilation pipelines: Prefer compiling
expressions with
cel-cpp,cel-go, orcel-javain a trusted pipeline rather than accepting arbitrary serializedParsedExprorCheckedExprProtobufs from untrusted callers. Maintain a mechanism to recompile stored ASTs in case a compiler bug is discovered or runtime invariants tighten. - Audit custom extensions and functions: Any custom function or extension registered in the runtime executes directly in the host C++ process. Callers are responsible for the memory safety, termination, and resource bounds of custom functions.
Different surfaces of cel-cpp operate under different trust assumptions.
Following the
Protocol Buffers Security Policy,
our threat model divides surfaces into three tiers:
These surfaces are actively hardened against adversarial inputs with structural defenses and continuous fuzzing.
- Security vulnerabilities identified in these paths are treated with high priority and are actively fixed.
- We avoid breaking changes whenever possible, but may introduce them when strictly necessary to close a security issue.
Defensive hardening is applied to these surfaces, but with weaker guarantees compared to proactively hardened surfaces.
- Serious security issues (such as memory corruption or RCE) are prioritized for fixing.
- We generally will not break backward compatibility guarantees to address lower-severity issues on these surfaces outside of major updates.
- When exposing these surfaces to potentially malicious inputs, callers should apply application-level isolation (such as sandboxing) or additional validation.
These surfaces are expected to be used with trusted inputs or are inherently sensitive to caller configuration.
- We maintain reasonable levels of defensive hardening where feasible so that sensible inputs do not crash, and we welcome bug reports and pull requests via public GitHub issues.
- However, crashes,
CHECKfailures, or resource exhaustion (DoS) reachable only through malicious inputs on these surfaces are not treated as security vulnerabilities.
Parsing (cel::Parser) and type checking (cel::TypeChecker) single CEL
expressions configured with the standard library are designed to handle
arbitrary, untrusted expression text, assuming defensive limits
(cel::ParserOptions and cel::CheckerOptions) are applied.
- Structural defenses: The parser enforces recursion depth, codepoint length, AST node count, and error recovery limits. The type checker uses iterative AST traversal and enforces expression node count, error count, and type nesting limits.
- Fuzzing: Lexing, parsing, and type checking are continuously fuzzed.
- Scope: Memory safety bugs (such as out-of-bounds reads/writes, use-after-free, or uncontrolled stack recursion) and crashes on arbitrary expression text with default limits are in scope for security reports.
Planning and evaluating ASTs that have been parsed and type-checked by a trusted
compilation pipeline (cel-cpp, cel-go, or cel-java) using the standard
library is proactively hardened against memory corruption and uncontrolled stack
recursion.
- Structural defenses: Both AST traversal during planning and program evaluation use iterative heap-based execution. The runtime is continuously fuzzed.
- Caveat on stored ASTs: Because we cannot guarantee the absence of
historical bugs in any compiler implementation, any pipeline that persists
and reuses
CheckedExprASTs should maintain a mechanism to recompile expressions from source. - Caveat on predictable runtime / DoS: Type checking guarantees type soundness, not bounded CPU or memory usage. Achieving predictable runtime guarantees requires careful environment design and caller-configured limits (see Resource Consumption and Denial of Service).
The runtime is somewhat hardened against arbitrary or unchecked ASTs (for
example, parse-only ASTs or ParsedExpr/CheckedExpr Protobufs deserialized
from untrusted sources), but it is not safe against maliciously constructed
ASTs:
- Optimization invariants:
cel::CreateOptimizedRuntimeBuilder(andcel::RuntimeOptions::enable_comprehension_list_append/enable_comprehension_mutable_map) relies on AST invariants established by standard macros and type checking. Hand-rolled or maliciously crafted ASTs that violate these invariants are unsafe with these options enabled. - Comprehension vulnerability check:
cel::EnableComprehensionVulnerabiltyCheckprovides partial defense-in-depth for custom or hand-written comprehension ASTs, but it is opt-in, non-exhaustive, and not intended for deeply nested ASTs. - Unbounded AST shapes: Externally deserialized ASTs bypass parser depth and node limits; deeply nested arbitrary ASTs may cause stack overflow during C++ object destruction or excessive resource usage during planning.
Applications that must accept serialized ASTs from untrusted sources should recompile from CEL source text instead, or validate and sandbox evaluation.
The CEL Policy compiler (policy/) composes multiple CEL expressions and
variables into a single program. While individual expressions are parsed and
type-checked, policy YAML parsing and multi-rule composition are not hardened
against adversarial policy authors.
The canonical CEL extensions (such as lists, strings, regex, sets,
bindings, encoders, math, protos, optional, and
two-var-comprehensions) offer more complex functions and macros than the
standard library, making them inherently more expensive to evaluate and more
susceptible to resource exhaustion. Enable only the extensions and versions
needed, and apply extension-specific limits and AST validation for untrusted
expressions:
- Lists (
cel::extensions::ListsCompilerLibrary): LowerListsExtensionOptions::max_range_sizefrom its default of1000000(for example, to100) to preventlists.range(n)from allocating large lists, and bound input list sizes before operations such asflatten,distinct,sort, andsortBy. - Strings (
cel::extensions::StringsCompilerLibrary): ConfigureStringsExtensionOptions::max_precision(default1000) forformat(), and bound input sizes forreplace,split, andjointo limit memory amplification. - Regex (
cel::extensions::RegexExtCompilerLibrary): SetRuntimeOptions::regex_max_program_sizeto a non-zero value and validate static patterns withRegexValidator. Be aware thatregex.replace(with capture-group backreferences) andregex.extractAllcan amplify output size relative to the input string. - Bindings (
cel::extensions::BindingsCompilerLibrary): Chainedcel.bindexpressions combined with concatenation (+) can produce exponential string or list growth in linear AST size (for example, repeated doubling). UseBindNestingLimitValidator(andAstDepthValidator) to restrict nesting when exposingcel.bindto untrusted expressions. - Sets and Two-Variable Comprehensions (
sets,two-var-comprehensions): Bound input collection sizes (set operations can be quadratic in list length) and keepcomprehension_max_iterationsandComprehensionNestingLimitValidatorenabled.
Parsing CEL environment configurations (cel::EnvConfigFromYaml) and CEL
policies (cel::YamlPolicyParser) assumes trusted (or vetted, semi-trusted)
authors:
- Underlying parser:
cel-cppdelegates YAML parsing toyaml-cpp, a non-memory-safe C++ library without a formal untrusted-input security model. Whilecel-cppapplies defensive post-parse validation where practical (such as duplicate-key, nesting-depth, and node-count checks inEnvConfigFromYaml), we make no security guarantees against malicious YAML inputs (including YAML alias/anchor amplification or parser bugs inyaml-cpp). - Environment expressiveness: Independent of YAML parsing bugs, a CEL environment configuration can define types, variables, and function overloads that make type checking or runtime evaluation unpredictably expensive (for example, deeply compounding generic type declarations).
- Cross-implementation field parity:
EnvConfigFromYamldoes not currently implement theimports,limits,validators, orfeaturesfields supported by other CEL implementations. Callers loading configurations authored forcel-goorcel-javashould setEnvConfigFromYamlOptions::strict = true(or inspectwarnings) to avoid silently ignoring safety limits.
Loading untrusted google::protobuf::DescriptorPool definitions or untrusted
custom type/function declarations is outside the threat model. Protobuf
descriptors are treated as trusted schemas (consistent with the
Protocol Buffers Security Policy).
Features explicitly documented as experimental or work-in-progress (for example,
cel::ParserOptions::enable_pratt_parser) are outside the threat model until
promoted to supported status.
Violating C++ API contracts—such as passing invalid pointers, dangling
absl::string_views, out-of-lifetime google::protobuf::Arena or
DescriptorPool references, or calling non-thread-safe builder APIs
concurrently—is an application integration error rather than a library
vulnerability.
Evaluating or validating the same CEL expression (or YAML environment
configuration) with different ParserOptions, CheckerOptions,
RuntimeOptions, library or extension versions, schemas, or CEL implementations
(cel-cpp, cel-go, cel-java) can produce different parse trees, type-check
results, or runtime outcomes. For example, options such as
enable_empty_wrapper_null_unboxing, enable_cross_numeric_comparisons,
enable_timestamp_duration_overflow_errors, use_json_field_names, or
differing standard library and extension versions intentionally change
evaluation semantics.
This risk also applies to stored CheckedExpr ASTs. Compiling an expression
once avoids parser and type-checker skew, but evaluating the same stored AST
under different RuntimeOptions, DescriptorPool schemas, library versions, or
runtime implementations can still produce different results. Likewise, an AST
produced by a newer compiler or a different implementation may rely on AST
extensions, overload IDs, or features that an older or different runtime either
rejects or interprets differently.
Additionally, behaviors that are not explicitly defined by the CEL specification
have no guarantees of consistency across implementations or library versions.
This includes the exact structure of ASTs, non-result side effects of
evaluation, and specific configuration options. Callers cannot assume that the
compilers or runtimes in cel-cpp, cel-go, and cel-java are exact drop-in
replacements for one another.
An architecture where one service validates an expression or configuration and forwards the raw text, or distributes a stored AST, to a downstream service that re-parses or evaluates it under different options, schemas, library versions, or implementations is outside the threat model.
For best security practice:
- Compile once in a trusted pipeline when possible, and keep runtime options,
DescriptorPoolschemas, extension versions, and library versions aligned across services that evaluate the resulting ASTs (with a mechanism to recompile stored ASTs on version upgrades). - Enable
EnvConfigFromYamlOptions::strict = truewhen loading YAML environment configurations shared across implementations so unsupported fields fail closed. - Enforce authorization decisions in the service performing the action rather than relying solely on upstream validation.
- If a system evaluates expressions across multiple runtimes or library versions, the integrator is responsible for validating that behaviors are consistent for their use case.
Configured limits (such as ParserOptions::max_recursion_depth,
ParserOptions::expression_node_limit,
CheckerOptions::max_expression_node_count,
CheckerOptions::max_type_decl_nesting, and
RuntimeOptions::comprehension_max_iterations) are defensive bounds intended to
prevent uncontrolled recursion and resource exhaustion. They are not guaranteed
to map exactly to specific syntactic input or output features (for example,
macro expansion or internal AST structure may cause effective counts to vary by
a constant factor).
Edge cases that exceed a configured limit slightly without exposing uncontrolled recursion or meaningful resource exhaustion are not considered security vulnerabilities or bugs, though we welcome reports and pull requests via public GitHub issues for minor updates to make enforcement more consistent. However, cases where recursion depth or resource consumption can scale non-linearly (or become unbounded) with respect to a configured limit are in scope as security issues.
Even for proactively hardened surfaces, CEL's non-Turing-complete design does not by itself guarantee bounded memory or CPU time for all expressions and inputs. Reports of CPU or memory exhaustion are not considered security vulnerabilities when they stem from:
- Unconfigured optional limits: For example, leaving
RuntimeOptions::regex_max_program_size = 0(unbounded), leavingListsExtensionOptions::max_range_sizeat its high default, disablingcomprehension_max_iterations, or omittingComprehensionNestingLimitValidator,BindNestingLimitValidator, orAstDepthValidatorwhen evaluating untrusted expressions. - Unbounded input or output growth: Combining large
Activationinputs with string concatenation (+), list concatenation (+),cel.bindchaining, or nested comprehensions without application-level input-size bounds or AST validators. - Expensive custom functions or environments: Custom functions, overloads, or extensions registered by the host application.
For latency- or memory-sensitive multi-tenant services evaluating untrusted
expressions, always combine cel-cpp's parser, checker, runtime, and extension
limits with AST validators and application-level input-size caps.