PT-2026-161323
Publicado
2026-11-19
·
Atualizado
2026-11-19
Descrição por
Pontuação
N/A
Não disponívelNão há classificações de severidade ou métricas disponíveis. Quando houver, atualizaremos as informações correspondentes na página.
Summary
Incorrect number comparison in OPA can cause wrong policy decisions, including wrongful authorization.
Affected numbers have a decimal point followed only by zeros, and an integer part that ends in zero (
100.0, 1000.00). OPA strips these trailing zeros before comparing, including the zeros in the integer part, so 100.0 is treated as equal to 1, 1000.00 to 1, and 20.0 to 2. The comparison goes wrong when the stripped value exactly matches the other operand. Numbers such as 105.0, 100.5 and 100 are not affected.Details
Which numbers are affected
A number is affected if it has a decimal point followed only by zeros, and an integer part that ends in zero (
100.0, 1000.00). Stripping 100.0, 1000.00, 20.0 and 30400.0 yields 1, 1, 2 and 304. Numbers whose integer part does not end in zero (105.0), whose decimal part contains a non-zero digit (100.5, 10.50), or that have no decimal point (100) are not affected.The comparison is wrong only if the stripped value exactly matches the other operand:
100.0 is mistaken for 1, but not for 10 or 2. The comparison is symmetric, so the affected number may be on either side. It does not have to come from the attacker: a policy constant or data value such as 100.0 can be matched by an attacker-supplied input value of 1.All comparison operators are affected, as is equality of arrays, objects and sets, and
max/min built-in functions. Rule indexing hides the problem in some rules that compare against a literal (see below), but this must not be relied upon.In v1.20.0 only numbers longer than 19 characters are affected, e.g.
100000000000000000000.0 == 1.Examples
Versions v1.10.0 - v1.19.x.
Operators. Literals only, evaluated as queries. The affected operators:
| Expression | Expected | Actual | Correct | Note |
|---|---|---|---|---|
100.0 == 1 | false | true | ❌ | 100.0 is trimmed to 1. The values are treated as equal |
100.0 != 1 | true | false | ❌ | 100.0 is trimmed to 1. The values are treated as equal |
100.0 > 1 | true | false | ❌ | 100.0 is trimmed to 1. The values are treated as equal, so neither is greater |
100.0 <= 1 | false | true | ❌ | 100.0 is trimmed to 1. The values are treated as equal, so <= holds |
100.0 >= 1 | true | true | ✅ | Correct, but only because the values are treated as equal and >= accepts equality. 100.0 is still trimmed to 1 |
100.0 < 1 | false | false | ✅ | Correct, but only because the values are treated as equal. 100.0 is still trimmed to 1 |
[100.0] == [1], {100.0} == {1}, {"a": 100.0} == {"a": 1} | false | true | ❌ | 100.0 is trimmed to 1. Elements are compared with the same logic |
max([100.0, 1]) | 100.0 | 1 | ❌ | 100.0 is trimmed to 1. The values are treated as equal, so max keeps the later element |
min([1, 100.0]) | 1 | 100.0 | ❌ | 100.0 is trimmed to 1. The values are treated as equal, so min keeps the later element |
max([1, 100.0]) | 100.0 | 100.0 | ✅ | Correct only because the larger value comes last. 100.0 is still trimmed to 1 |
max([1, 100.0]) == 1 | false | true | ❌ | max returns the correct 100.0; the following == is what fails |
100.0 == 10 | false | false | ✅ | The stripped value 1 does not match 10 |
100.1 == 1 | false | false | ✅ | 100.1 ends in a non-zero digit, so nothing is trimmed |
123.0 == 1 | false | false | ✅ | The integer part of 123.0 ends in a non-zero digit, so only the .0 is trimmed |
Where the number comes from. The affected number may originate from
input (typically attacker-controlled), the policy, or data, and may be either operand of the comparison, or both:| Trailing zeros in | Policy expression | Input / data | Expected | Actual | Correct | Note |
|---|---|---|---|---|---|---|
| input | input.x == data.limit | data.limit = 1, input.x = 100.0 | false | true | ❌ | 100.0 is trimmed to 1, which equals data.limit |
| input | max([input.x, 1]) | input.x = 100.0 | 100.0 | 1 | ❌ | The values are treated as equal, so max keeps the later element |
| policy | input.x >= 100.0 | input.x = 1 | false | true | ❌ | 100.0 is trimmed to 1, which equals input.x, so >= holds |
| policy | input.x >= 100.0 | input.x = 2 | false | false | ✅ | The stripped value 1 does not match 2, so the numeric comparison is used |
| data | input.x == data.limit | data.limit = 100.0, input.x = 1 | false | true | ❌ | 100.0 is trimmed to 1 |
| input and data | input.x == data.limit | data.limit = 1000.0, input.x = 10.0 | false | true | ❌ | 1000.0 and 10.0 are both trimmed to 1 |
Effect of rule indexing
OPA indexes rules that compare a base document reference with a literal, such as
input.x == 1. When a rule is resolved by the index, the rule body is skipped for non-matching input and the faulty comparison is never evaluated. This reduces the exposed surface, but it is an optimization and not a mitigation: whether it applies depends on the shape of the rule, and small changes to a policy can turn it off.| Policy | Input / data | Expected | Actual | Correct | Note |
|---|---|---|---|---|---|
Query: input.x == 1 | input.x = 100.0 | false | true | ❌ | Queries are not indexed |
Rule: allow if input.x == 1 | input.x = 100.0 | false | false | ✅ | Resolved by the index; the body is not evaluated |
Rule: allow if { input.x > 0; input.x == 1 } | input.x = 100.0 | false | false | ✅ | The equality is the last expression on input.x, so it is indexed |
Rule: allow if { input.x == 1; input.x > 0 } | input.x = 100.0 | false | true | ❌ | A later expression that passes input.x to a function or operator, or assigns it, makes the index accept any value for input.x; and the equality is then also evaluated |
Rule: allow if input.x == data.limit | input.x = 100.0, data.limit = 1 | false | true | ❌ | Only comparisons with literals are indexed |
Comparisons that are not
== against a literal (ordering operators, !=, data or computed values, collections, max/min) are not indexed and are affected as described above.Workarounds
If upgrading is not possible:
- Reject or rewrite numbers in
inputwhose decimal part consists only of zeros (100.0,1000.00) before they reach OPA. Numbers with a non-zero decimal digit (100.5) need no handling. - Avoid writing integral values with a zero-only decimal part in
dataand policy (100, not100.0). This does not protect againstinputvalues written that way.
Proof of concept
Run with the released
opa v1.10.0 binary. Each command prints the wrong result on v1.10.0 – v1.19.x and the correct result on v1.20.1 and later.1. Literals only
$ opa eval -fpretty '100.0 == 1'
true # expected: false
$ opa eval -fpretty '100.0 <= 1'
true # expected: false
$ opa eval -fpretty 'max([100.0, 1])'
1 # expected: 100.02. Equality against
data: wrongful authorizationpolicy.rego:rego
package authz
default allow := false
allow if input.role id == data.admin role iddata.json: {"admin role id": 1}$ echo '{"role id": 10.0}' | opa eval -fpretty -d policy.rego -d data.json -I data.authz.allow
true # expected: false
$ echo '{"role id": 10}' | opa eval -fpretty -d policy.rego -d data.json -I data.authz.allow
false # correct: an integer is not affectedThe attacker supplies
10.0, which is stripped to 1 and matches admin role id.Impact
Who is impacted: anyone running an affected version of OPA (as a server, library or through the Go SDK, including embedded use such as Envoy, Kubernetes admission control or custom authorization services) whose policies compare a number that an attacker can influence with another number. The attacker does not need to control the trailing zeros on both sides: a policy constant or
data value such as 100.0 can be matched by a plain integer 1 in the input, and an input value such as 100.0 can match a policy constant 1. Policies that only compare integers written without a decimal point, or that never compare caller-influenced numbers, are not affected.Consequences: OPA returns an incorrect evaluation result (integrity of the decision). Depending on the policy this is an authorization bypass, a wrongful denial, or other wrongful policy result. There is no direct effect on OPA's own confidentiality, integrity or availability; the impact falls on the relying application, whose protected data and operations are exposed by a wrong allow.
Fornecedores
Produtos afetados
Identificadores relacionados
Encontrou algum problema na descrição? Tem algo a acrescentar? Fique à vontade para nos escrever 👾