Skip to main content
Menu
Advisories

Non-terminal sibling relations can result in incorrect Check responses for a relationship whose expiration time is in the past

GHSA-W278-32QG-48Q5Published Updated GitHub

Description

An error in code that optimizes the behavior of SpiceDB checks resulted in expired relationships being included in the computation of permissionship under specific circumstances. When a relation was defined as the union (|) of a type with expiration (e.g. foo with expiration) and that same type with a nonterminal subject relation (e.g. foo#bar), a check over that relation would discard the expiration. This could result in incorrect permission checks if the expiration of one of those relationships had passed, up to the time when that relationship is garbage collected.

Details

One optimization in SpiceDB is that if a check of a particular relationship doesn't require considering the expiration of the relationship, it doesn't include expiration in the datastore query. SpiceDB does a similar optimization if it determines that a caveat isn't involved either.

In the check path, this is computed by asking whether the count of direct subjects and wildcards without expiration is equal to the total count of direct subjects and wildcards. However, the count logic was incorrect for relations whose subject relation matched the type of the relation itself.

For the purposes of this discussion, asking whether the "direct subject" of a relation matches the subject of a check is asking whether the subject of the check matches the type defined in the relation. If you're asking whether a user can view a document in the check, you're asking whether the type referenced in the relation is exactly user.

If we're considering the schema below together with this code block, both user with expiration and user#manager match the condition defined on line 341, but user#manager should not be counted as a "direct subject" for this logic. This code was looking at user with expiration and saying "that is a direct subject with an expiration" and it was looking at user#manager and saying "that is a direct subject without expiration." Instead, it should have been looking at user#manager and saying "this is not a direct subject."

This misinterpretation led to the expiration check getting skipped here, and an expired relationship being returned for the check when it should not have been returned.

Exposure Window

Postgres and MySQL both run with a 3m GC interval by default. Spanner and CockroachDB both use row-level TTLs which run a cleanup job once daily by default. Outside of your datastore's window you are not affected.

Proof of concept

This schema:

use expiration

definition user {
relation manager: user
}

definition document {
relation viewer: user with expiration | user#manager
permission view = viewer
}

And this relationship:

document:somedoc#viewer@user:alice[expiration:2020-01-01T00:00:00Z]

Will result in this check:

document:somedoc#view@user:alice

returning HAS_PERMISSION incorrectly.

Impact

If all of these apply:

  • You have a relation declaration that uses with expiration
  • It is unioned (| operator) with the same type as the with expiration type
  • That unioned type references a different relation or permission using #

Then a check for a permission that references an expired relationship can result in the inclusion of that expired relationship, resulting in an incorrect permission evaluation. See the Proof of Concept for a concrete example.

Reported by Sathwik Yadlapati.

Affected versions

References

GitHub · authzed/spicedb