fix(cloudflare/state-store): treat JSON decode failures as unreadable entries - #1399
Open
its-rosetta wants to merge 1 commit into
Open
fix(cloudflare/state-store): treat JSON decode failures as unreadable entries#1399its-rosetta wants to merge 1 commit into
its-rosetta wants to merge 1 commit into
Conversation
… entries AES-CTR decryption with a wrong key usually does not throw in Web Crypto - it yields random plaintext bytes. The existing beta.45 key-rotation tolerance only catches crypto.subtle.decrypt failures, so JSON.parse of that garbage escapes the try block and, via Effect.orDie, kills the whole deploy with an unrecoverable defect instead of the intended return-undefined reconciliation path. Move the parse inside the try so wrong-key entries degrade the same way decrypt failures already do. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
decryptEntryin the Cloudflare state store tolerates decryption failures (the 2.0.0-beta.45 key-rotation situation) by returningundefined— but only whencrypto.subtle.decryptitself throws. For AES-CTR, a wrong key typically does not throw: it yields random plaintext bytes.JSON.parseof those bytes sits outside thetry, so the resultingSyntaxErrorescapes intoEffect.orDieand kills the entire deploy with an unrecoverable defect, instead of taking the intended return-undefinedreconciliation path.We hit this in production against entries written around the beta.45 key rotation; we have been carrying this exact fix as a
patchedDependenciespatch since June and it has been load-bearing since.Fix
Move the
JSON.parseinside the existingtryso wrong-key garbage degrades identically to a decrypt failure (logged, entry treated as unreadable, engine reconciles). Two-line move plus comment; no behavior change for healthy entries.🤖 Generated with Claude Code