Merged
Conversation
the siphash keys were hardcoded as 0xdeadbeaf and 0xfaebdaed. anyone can read these from the source and craft inputs that hash to the same bit positions, filling the filter faster and raising false positives. add NewWithKeys(k0, k1, ...) so callers can supply their own random keys (e.g. generated once per node). this restores the collision resistance that siphash is designed to provide. - sipHash.go: extract siphash constants and default keys, read k0/k1 from the Bloom struct instead of using hardcoded values - bbloom.go: add k0/k1 fields, add NewWithKeys constructor, persist custom keys in JSON (omitted when using defaults) - bbloom_test.go: tests for custom keys, JSON round-trip with custom keys, default keys omitted from JSON - doc.go: mention NewWithKeys for untrusted data
marshal() was storing pointers to bl.k0/bl.k1 in the export struct. In JSONMarshalTS, json.Marshal dereferences these pointers outside the read lock, creating a potential data race.
- use it in JSONUnmarshal, requiring both K0 and K1 to be present
marshal() always writes both keys or neither, but hand-edited or corrupted JSON could contain only one. silently falling back to default keys in that case would produce a filter that cannot find its own entries. error early instead.
callers treating keys as secret should know they are included verbatim in the serialized filter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
the siphash keys were hardcoded as
0xdeadbeafand0xfaebdaed. anyone can read these from the source and craft inputs that hash to the same bit positions, filling the filter faster and raising false positives.add
NewWithKeys(k0, k1, ...)so callers can supply their own random keys (e.g. generated once per node). this restores the collision resistance that siphash is designed to provide.NewWithKeysconstructor, persist custom keys in JSON (omitted when using defaults)NewWithKeysfor untrusted data