Validate curve points in PublicKeyFromBytes [PAY-2108]#199
Merged
Conversation
Add IsOnCurve check to reject invalid elliptic curve points at parse time, preventing crypto/elliptic.ScalarMult panics in Go 1.24+. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add explanatory comments to the IsOnCurve check and test helpers to clarify the Go 1.24+ ScalarMult panic context for reviewers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
yanyi-wego
approved these changes
Apr 10, 2026
Contributor
yanyi-wego
left a comment
There was a problem hiding this comment.
LGTM. The IsOnCurve guard is correctly placed in PublicKeyFromBytes, rejects off-curve points before ECDH, and the tests cover the bytes, base64, and hex parsing paths.
🤖 Reviewed and generated with Claude Opus 4.6 (1M context)
kates-wego
approved these changes
Apr 13, 2026
lei-wego
approved these changes
Apr 13, 2026
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.
Summary
IsOnCurvevalidation toPublicKeyFromBytesto reject invalid elliptic curve points at parse timecrypto/elliptic.ScalarMultpanics introduced in Go 1.24+ when input points are not on the curvePublicKeyFromPEMBytes/File/String) already validate viax509.ParsePKIXPublicKey— no changes neededContext
Production panic (PD Q2Z7JW0X8JIFID) caused by
crypto/elliptic.Curve.ScalarMultpanicking on invalid curve points after Go version bump.PublicKeyFromBytesparsed X,Y coordinates without validating they are on the curve. When corrupted/malformed encrypted data is received, the embedded ephemeral public key may not be on P521, causing a panic in ECDH shared secret computation.Changes
encryption/ecies/publickey.go: Addcurve.IsOnCurve(x, y)check inPublicKeyFromBytesbefore constructing thePublicKeyencryption/ecies/publickey_test.go: Add tests forPublicKeyFromBytes,PublicKeyFromBase64, andPublicKeyFromHexwith off-curve points (X=1, Y=1 on P521)Test plan
Test_PublicKeyFromBytes_InvalidCurvePoint— returns error, not panicTest_PublicKeyFromBase64_InvalidCurvePoint— returns error, not panicTest_PublicKeyFromHex_InvalidCurvePoint— returns error, not panic🤖 Generated with Claude Code