You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: avoid hash collision in caveat context (#3065)
## Description
Someone pointed out to us that if you use a nested list of lists in a
caveat context, it was possible under our current serialization and
hashing logic to have a serialization collision and therefore a dispatch
cache hash collision.
This fixes that by using deterministic proto marshalling of the caveat
context Struct object.
## Changes
* Update `context_hash.go` to use deterministic marshalling
* Propagate the error signature change through the stack
* change `hashableContext` to `hashableContextString` to satisfy the
interface
## Testing
Review
---------
Co-authored-by: Maria Ines Parnisari <maria.ines.parnisari@authzed.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
22
22
- Upgraded the spanner client, which changed the internal implementation to not use a session pool. This means that the `--datastore-spanner-max-sessions` and `--datastore-spanner-min-sessions` flags are now deprecated and no-op. We also strongly recommend using [Application Default Credentials](https://docs.cloud.google.com/docs/authentication/client-libraries#adc) in favor of a credentials file. (https://github.com/authzed/spicedb/pull/3038)
23
23
- Query Planner: error `"ERROR: index \"pk_relation_tuple\" cannot be used for this query (SQLSTATE 42809)"` returned when using wildcards (https://github.com/authzed/spicedb/pull/3039)
24
24
- Providing one of (`--grpc-tls-cert-path`, `--grpc-tls-key-path`) but not the other is now considered an error state, as both are necessary if you want to use TLS.
25
+
- In a caveat context that uses nested lists of lists, the hashes generated for cache keys could collide because of an issue with the serialization logic. The serialization now uses deterministic protobuf serialization which avoids this issue (https://github.com/authzed/spicedb/pull/3065)
hashableContext{HashableContext: caveats.HashableContext{Struct: req.Context}}, // NOTE: context is included here because lookup does a single dispatch
85
+
hashableContextString(stableContextString),
82
86
hashableCursor{req.OptionalCursor},
83
87
hashableLimit(req.OptionalLimit),
84
-
)
88
+
), nil
85
89
}
86
90
87
91
// lookupResourcesRequest3ToKey converts a lookup request into a cache key
hashableContext{HashableContext: caveats.HashableContext{Struct: req.Context}}, // NOTE: context is included here because lookup does a single dispatch
102
+
hashableContextString(stableContextString), // NOTE: context is included here because lookup does a single dispatch
95
103
hashableCursorSections{req.OptionalCursor},
96
104
hashableLimit(req.OptionalLimit),
97
-
)
105
+
), nil
98
106
}
99
107
100
108
// lookupSubjectsRequestToKey converts a lookup subjects request into a cache key
0 commit comments