cedar-policy / cedar

Implementation of the Cedar Policy Language
https://www.cedarpolicy.com
Apache License 2.0
864 stars 78 forks source link

Empty context panic in cedar-policy 3.0.0 #524

Closed tomtau closed 10 months ago

tomtau commented 10 months ago

Before opening, please confirm:

Bug Category

Policy Evaluation

Describe the bug

In Cedar 3.0, we suddenly started to get this panic with a confusing error message:

empty set of keys cannot contain a duplicate key: Evaluation(EvaluationError { error_kind: RecursionLimit, advice: None }) thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cedar-policy-core-3.0.0/src/ast/request.rs:198:14:

Expected behavior

Context::empty shouldn't panic based on this safety comment: https://github.com/cedar-policy/cedar/blob/818aefbbc4943c51a411951f5f9c3388df1842a6/cedar-policy-core/src/ast/request.rs#L196

Reproduction steps

As with https://github.com/cedar-policy/cedar/issues/322 , it occurs when executing cedar-policy within a sizeable Axum web application running on AWS Lambda.

Code Snippet

Context::empty()

Log output

empty set of keys cannot contain a duplicate key: Evaluation(EvaluationError { error_kind: RecursionLimit, advice: None })
thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cedar-policy-core-3.0.0/src/ast/request.rs:198:14:

Additional configuration

AWS Lambda (Amazon Linux 2 custom runtime / cargo-lambda)

Operating System

No response

Additional information and screenshots

Similarly to https://github.com/cedar-policy/cedar/issues/322 , the workaround is to wrap the Context::empty call inside stacker::grow.

tomtau commented 10 months ago

(The same behaviour is for a Context with a single pair that shouldn't return an error, given there's only a single pair.)

cdisselkoen commented 10 months ago

Thanks for filing this issue. We are investigating potential fixes.