The vulnerability in SpiceDB's LookupResources API (GHSA-9m7r-g8hg-x3vr) caused it to return incomplete results for certain schema configurations. My analysis of the patch reveals two underlying logical flaws that were fixed.
First, in pkg/schema/reachabilitygraph.go, the collectEntrypoints function used an overly aggressive memoization strategy. When a permission involved a union that referenced the same relation in multiple ways (e.g., permission view = viewer + viewer->special_user), the function would prematurely stop its analysis after encountering the viewer relation the first time. This prevented it from discovering the additional path through the viewer->special_user arrow, leading to an incomplete set of entrypoints for the LookupResources query.
Second, in pkg/query/build_tree.go, the buildArrowIterators and buildIntersectionArrowIterators functions, which build the query plan, did not correctly handle relations that could resolve to multiple types (e.g., relation viewer: user | group). If an arrow was applied to such a relation, and the target of the arrow did not exist on all of the possible types, the function would error out instead of correctly treating it as an empty result for the non-applicable types. This error would halt query construction for that path, again leading to incomplete results.
The patch addresses both issues by refining the memoization logic in collectEntrypoints to allow for the exploration of all paths and by making the arrow-building functions correctly handle multi-typed relations by treating missing arrow targets as empty sets. These changes ensure that the query planner and reachability analysis can correctly process these complex schema structures, remediating the vulnerability.