feat: WithStrictDecode to reject lossy client signal decodes#116
Merged
Conversation
A client value that overflowed a Signal[T]'s narrower numeric type (e.g. 9999 into Signal[int8]) was silently truncated, and a shape mismatch was silently dropped — the typed Signal was only as safe as a best-effort decode. Add WithStrictDecode(): a client value that overflows the target int/uint/float width or whose JSON shape doesn't match the field surfaces an action error and the handler does not run, so corrupt input can't reach server state. Off by default (best-effort decode preserved). The decode is factored into decodeScalarChecked, which reports the error; decodeScalarInto wraps it and discards it so server-side store decodes keep the lenient contract. The struct-tag init path stays best-effort (author input, not untrusted client).
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.
Critic panel finding #4 (major; raised 3×). A client value overflowing a
Signal[T]'s narrower numeric type (e.g.9999intoSignal[int8]) was silently truncated; a shape mismatch silently dropped. The typed Signal was only as safe as a best-effort decode.Change
WithStrictDecode(): a client value that overflows the target int/uint/float width, or whose JSON shape doesn't match the field, surfaces an action error and the handler does not run — corrupt input can't reach server state.Decode is factored into
decodeScalarChecked(reports the error);decodeScalarIntowraps + discards it so server-side store decodes (StateSess/StateTab from the backplane) keep the lenient contract. The struct-taginit=path stays best-effort (author input, not untrusted client). Off by default.Tests
Full
ci-check.shgreen.