Repository navigation
fix: split Tempo WebAuthn data in linear time - #676
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
|
Published pnpm add ox@pr-676
pnpm add [email protected] |
Merged
This branch had an error being deployed
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.
SignatureEnvelope.deserializeandSignatureEnvelope.fromRpcinox/tempo, and theox/zod/temposchema, found the start ofclientDataJSONby trying every split offset from 37 and decoding the rest ofwebauthnDataeach time. That is quadratic in the size of the data. Under the 2048-byte limit from #654 an envelope with no valid JSON cost 8 to 22 ms to reject, against 0.03 ms for a valid one.clientDataJSONis the JSON object that ends at the last byte, so one backward pass finds the brace that pairs with that byte and oneJSON.parsevalidates the object. The three copies of the loop now sharesrc/tempo/internal/webauthnData.ts. The worst inputs at the limit take 0.02 to 0.04 ms, and without the limit the helper takes 3 to 10 ms for 1 MiB.Behaviour
Compared against the old loop on 1.9 million generated inputs (random bytes, valid JSON after varied authenticator data, mutations, malformed hex): same result and same thrown error class on every input, with one exception. When a UTF-8 byte order mark sits directly before the JSON, the old loop split before the mark, so the three bytes were lost when the envelope was serialized again. They now stay in
authenticatorData. Tempo's node rejects such an envelope either way, because it readsauthenticatorDataas exactly 37 bytes.Tests
The new tests count the bytes passed to
TextDecoder.decodeandJSON.parsefor an envelope of nested, unterminated objects, and fail without the fix (1,764,381 bytes decoded against a bound of 1,878). They count work instead of time because the size limit keeps the old cost in milliseconds, where a time threshold would be flaky.The same fix for
0.x: #677