ibc-apps
ibc-apps copied to clipboard
fix(ibc-hooks): safely construct JSON message using Go struct and json.Marshal
This pull request addresses a potential security on issue #277 and reliability issue related to manual JSON string construction with interpolated, user-controlled values. Previously, the OnAcknowledgementPacketOverride method built the sudoMsg JSON payload using fmt.Sprintf, directly interpolating the ackAsJson value into a JSON string. This approach risks incorrect JSON formatting and potential injection vulnerabilities.
Changes
- Replaced manual JSON string construction with a structured approach.
- Introduced a Go struct representing the message payload.
- Used
json.Marshalto safely encode the struct into JSON, ensuring proper escaping and quoting of all fields.
This change improves code safety, maintainability, and ensures compliance with Go’s best practices for JSON handling.
Affected Area
- https://github.com/cosmos/ibc-apps/blob/5596e0a0358565b87fa6399125bbfc8dbdf97553/modules/ibc-hooks/wasm_hook.go#L307-L309 specifically the
OnAcknowledgementPacketOverridemethod.
/cc @gjermundgaraba. I kindly request that you urgently consider merging this pull request at your earliest convenience.