Worker: fix potentially incorrect signatures for some small payloads #742
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.
There was an issue with small payloads (well potentially larger too, but exceedingly unlikely) which could cause the payloads to not serialize correctly which could cause signatures to be incorrect in same rare scenarios likely only affecting small payloads.
If memory serves, serde parses and stringifies json in a non-deterministic way. Normally it would be deterministic, but it also maintains an internal cache of "json structures", and if it thinks that it can reuse one it does. This means that if there's a "cache hit", which I'm not sure about the circumstances, it can reuse one of those and therefore generate a different string.
Why does it matter? Because instead of using the string representation of the payload, we were passing a
Json::Value
around and stringifying and parsing it in multiple places. This is both inefficient, and incorrect. Cryptographic hashes (like the ones used by the Svix signature scheme) are very sensitive to even the slightest changes, not to mention reordering, so we must use the same payload everywhere. We can't just hope it'll be the same when strinigifying later.