The vulnerability lies in a flawed serialization mechanism for caveat contexts that contain nested lists, leading to potential hash collisions in cache keys. This could allow an attacker to poison the cache and cause SpiceDB to return incorrect, permissive authorization decisions.
The root cause is the pkg/caveats.StableContextStringForHashing function, which implemented a custom, vulnerable serialization logic. This logic did not uniquely represent distinct nested list structures, causing different contexts to produce identical strings for hashing.
The patch addresses this by completely replacing the custom serialization with a call to the deterministic marshaller from Google's protobuf library (proto.MarshalOptions{Deterministic: true}). This ensures that any two different context structures will produce different byte representations, thus preventing hash collisions.
The vulnerability affected multiple parts of the system that rely on caching and use this hashing function. The analysis identified the key functions that were directly using the vulnerable logic to generate cache keys for LookupResources (keys.lookupResourcesRequest2ToKey, keys.lookupResourcesRequest3ToKey) and CheckBulkPermissions (v1.computeCallHash) requests. These are the functions that would appear in a runtime profile when the vulnerability is triggered.