Skip to content

fix(cloudflare/state-store): treat JSON decode failures as unreadable entries - #1399

Open
its-rosetta wants to merge 1 commit into
alchemy-run:mainfrom
its-rosetta:fix/state-store-decode-tolerance
Open

fix(cloudflare/state-store): treat JSON decode failures as unreadable entries#1399
its-rosetta wants to merge 1 commit into
alchemy-run:mainfrom
its-rosetta:fix/state-store-decode-tolerance

Conversation

@its-rosetta

Copy link
Copy Markdown

Problem

decryptEntry in the Cloudflare state store tolerates decryption failures (the 2.0.0-beta.45 key-rotation situation) by returning undefined — but only when crypto.subtle.decrypt itself throws. For AES-CTR, a wrong key typically does not throw: it yields random plaintext bytes. JSON.parse of those bytes sits outside the try, so the resulting SyntaxError escapes into Effect.orDie and kills the entire deploy with an unrecoverable defect, instead of taking the intended return-undefined reconciliation path.

We hit this in production against entries written around the beta.45 key rotation; we have been carrying this exact fix as a patchedDependencies patch since June and it has been load-bearing since.

Fix

Move the JSON.parse inside the existing try so 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

… 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>
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