Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker: fix potentially incorrect signatures for some small payloads #742

Merged
merged 1 commit into from
Dec 27, 2022

Conversation

tasn
Copy link
Member

@tasn tasn commented Dec 27, 2022

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.

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.
@tasn tasn changed the title Worker: fix small payload serialization for signatures Worker: fix potentially incorrect signatures for some small payloads Dec 27, 2022
@tasn tasn merged commit f4457a2 into main Dec 27, 2022
@tasn tasn deleted the tom/worker-payload branch December 27, 2022 23:37
tasn added a commit that referenced this pull request Dec 27, 2022
…742)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants