Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1oY3czLWo3NG0tcWM1OM0p2Q
Incorrect Calculation in github.com/open-policy-agent/opa
Impact
Under certain conditions, pretty-printing an AST that contains synthetic nodes could change the logic of some statements by reordering array literals. Example of policies impacted are those that parse and compare web paths, see the example below.
All of these three conditions have to be met to create an adverse effect:
- An AST of Rego had to be created programmatically such that it ends up containing terms without a location (such as wildcard variables).
- The AST had to be pretty-printed using the
github.com/open-policy-agent/opa/format
package. - The result of the pretty-printing had to be parsed and evaluated again via an OPA instance using the bundles, or the Golang packages.
If any of these three conditions are not met, you are not affected.
Notably, all three would be true if using optimized bundles, i.e. bundles created with opa build -O=1
or higher.
In that case, the optimizer would fulfil condition (1.), the result of that would be pretty-printed when writing the bundle to disk, fulfilling (2.). When the bundle was then used, we'd satisfy (3.).
Example
For example, the process outlined above could turn
this rule
hello {
["foo", _] = split(input.resource, "/")
}
into
hello {
[_, "foo"] = split(input.resource, "/")
}
with an input of
{
"resource": "foo/bar"
}
the result would change from
{
"hello": true
}
to (no default value of hello)
{}
The severity was determined to be moderate because the conditions are quite particular. Please note that its only the OPA bundle build process thats affected. An OPA sidecar of version 0.36.0 with an optimized bundle built by OPA 0.32.1 would not face this bug.
Patches
Fixed in version 0.37.2.
Workarounds
- Disabling optimization when creating bundles.
References
- Introduced in https://github.com/open-policy-agent/opa/pull/3851
- Backported for the 0.33.1 patch release: https://github.com/open-policy-agent/opa/commit/bfd984ddf93ef2c4963a08d4fdadae0bcf1a3717
- Fixed by https://github.com/open-policy-agent/opa/commit/932e4ffc37a590ace79e9b75ca4340288c220239 and https://github.com/open-policy-agent/opa/commit/2bd8edab9e10e2dc9cf76ae8335ced0c224f3055
For more information
If you have any questions or comments about this advisory:
- Open an issue in Community Discussions
- Ask in Slack: https://slack.openpolicyagent.org/
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1oY3czLWo3NG0tcWM1OM0p2Q
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: about 2 years ago
Updated: about 1 year ago
CVSS Score: 6.3
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L
Identifiers: GHSA-hcw3-j74m-qc58, CVE-2022-23628
References:
- https://github.com/open-policy-agent/opa/security/advisories/GHSA-hcw3-j74m-qc58
- https://github.com/open-policy-agent/opa/pull/3851
- https://github.com/open-policy-agent/opa/commit/932e4ffc37a590ace79e9b75ca4340288c220239
- https://github.com/open-policy-agent/opa/commit/bfd984ddf93ef2c4963a08d4fdadae0bcf1a3717
- https://nvd.nist.gov/vuln/detail/CVE-2022-23628
- https://github.com/open-policy-agent/opa/commit/2bd8edab9e10e2dc9cf76ae8335ced0c224f3055
- https://pkg.go.dev/vuln/GO-2022-0316
- https://github.com/advisories/GHSA-hcw3-j74m-qc58
Blast Radius: 20.8
Affected Packages
go:github.com/open-policy-agent/opa
Dependent packages: 852Dependent repositories: 2,039
Downloads:
Affected Version Ranges: >= 0.33.1, < 0.37.2
Fixed in: 0.37.2
All affected versions: 0.33.1, 0.34.0, 0.34.1, 0.34.2, 0.35.0, 0.36.0, 0.36.1, 0.37.0, 0.37.1
All unaffected versions: 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.4.8, 0.4.9, 0.4.10, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5.6, 0.5.7, 0.5.8, 0.5.9, 0.5.10, 0.5.11, 0.5.12, 0.5.13, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.9.0, 0.9.1, 0.9.2, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5, 0.10.6, 0.10.7, 0.11.0, 0.12.0, 0.12.1, 0.12.2, 0.13.0, 0.13.1, 0.13.2, 0.13.3, 0.13.4, 0.13.5, 0.14.0, 0.14.1, 0.14.2, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.17.2, 0.17.3, 0.18.0, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.20.4, 0.20.5, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.23.2, 0.24.0, 0.25.0, 0.25.1, 0.25.2, 0.26.0, 0.27.0, 0.27.1, 0.28.0, 0.29.0, 0.29.1, 0.29.2, 0.29.3, 0.29.4, 0.30.0, 0.30.1, 0.30.2, 0.31.0, 0.32.0, 0.32.1, 0.33.0, 0.37.2, 0.38.0, 0.38.1, 0.39.0, 0.40.0, 0.41.0, 0.42.0, 0.42.1, 0.42.2, 0.43.0, 0.43.1, 0.44.0, 0.45.0, 0.46.0, 0.46.1, 0.46.2, 0.46.3, 0.47.0, 0.47.1, 0.47.2, 0.47.3, 0.47.4, 0.48.0, 0.49.0, 0.49.1, 0.49.2, 0.50.0, 0.50.1, 0.50.2, 0.51.0, 0.52.0, 0.53.0, 0.53.1, 0.54.0, 0.55.0, 0.56.0, 0.57.0, 0.57.1, 0.58.0, 0.59.0, 0.60.0, 0.61.0