Skip to content

fix: split Tempo WebAuthn data in linear time - #676

Merged
jxom merged 1 commit into
mainfrom
fix/tempo-webauthn-linear-parse
Nov 12, 2026
Merged

jxom merged 1 commit into
mainfrom
fix/tempo-webauthn-linear-parse

Conversation

@jxom

@jxom jxom commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

SignatureEnvelope.deserialize and SignatureEnvelope.fromRpc in ox/tempo, and the ox/zod/tempo schema, found the start of clientDataJSON by trying every split offset from 37 and decoding the rest of webauthnData each 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.

clientDataJSON is the JSON object that ends at the last byte, so one backward pass finds the brace that pairs with that byte and one JSON.parse validates the object. The three copies of the loop now share src/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 reads authenticatorData as exactly 37 bytes.

Tests

The new tests count the bytes passed to TextDecoder.decode and JSON.parse for 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

@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ox Error Error Nov 12, 2026 4:39am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T04:38:49.616498Z ac22b18 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

Published [email protected] under the pr-676 dist-tag, which follows this pull request until it closes.

pnpm add ox@pr-676
pnpm add [email protected]

@jxom
jxom merged commit 53558ba into main Nov 12, 2026
14 of 15 checks passed
@jxom
jxom deleted the fix/tempo-webauthn-linear-parse branch November 12, 2026 05:05
@github-actions github-actions Bot mentioned this pull request Nov 12, 2026

This branch had an error being deployed

1 failed deployment
Preview — ac22b187 Deployed Nov 12, 2026 by vercel[bot]
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.

2 participants