Skip to content

strkey: validate payload length in DecodeSignedPayload to prevent panic#5909

Merged
karthikiyer56 merged 1 commit intomainfrom
karthik/fix-bug-in-p-address-strkey-parsing
Feb 19, 2026
Merged

strkey: validate payload length in DecodeSignedPayload to prevent panic#5909
karthikiyer56 merged 1 commit intomainfrom
karthik/fix-bug-in-p-address-strkey-parsing

Conversation

@karthikiyer56
Copy link
Contributor

strkey.Decode() accepts payloads of any length with valid checksums. Without length validation, short P-addresses could pass DecodeSignedPayload() and later cause panics when slicing for the 32-byte signer key.

Add explicit length check before slicing to reject malformed signed payloads early with a descriptive error.

This fixes issue #5902

strkey.Decode() accepts payloads of any length with valid checksums.
Without length validation, short P-addresses could pass DecodeSignedPayload()
and later cause panics when slicing for the 32-byte signer key.

Add explicit length check before slicing to reject malformed signed
payloads early with a descriptive error.
Copilot AI review requested due to automatic review settings February 19, 2026 03:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a panic vulnerability in strkey.DecodeSignedPayload() when processing malformed P-addresses with payloads shorter than 32 bytes. The function previously attempted to slice the first 32 bytes for the signer key without validating length, causing a runtime panic on short inputs.

Changes:

  • Added length validation in DecodeSignedPayload() to reject payloads shorter than 32 bytes before slicing
  • Added comprehensive test coverage for edge cases (0, 10, and 31 byte payloads) to verify rejection with appropriate error messages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
strkey/signed_payload.go Added length check before slicing to prevent panic when raw payload is shorter than 32 bytes
strkey/signed_payload_test.go Added test to verify short raw payloads are rejected with descriptive error message

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@karthikiyer56 karthikiyer56 requested a review from a team February 19, 2026 04:57
@karthikiyer56 karthikiyer56 merged commit fc598db into main Feb 19, 2026
17 checks passed
Comment on lines +63 to +65
if len(raw) < signerLen {
return nil, errors.Errorf("signed payload too short: %d bytes", len(raw))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length in the core and rust impls actually require an inner payload length of 1.

But that seems out of scope to fix in this pr since this Pr is just fixing the unsafe slicing causing the panic. But fyi none the less and maybe we should make the Go impl more similar to the others in a future change.

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.

4 participants