Skip to content

fix(rpc): Validate accepts object params, not just arrays#14

Merged
kuny0707 merged 1 commit into
masterfrom
fix/validate-object-params
Jul 14, 2026
Merged

fix(rpc): Validate accepts object params, not just arrays#14
kuny0707 merged 1 commit into
masterfrom
fix/validate-object-params

Conversation

@ety001

@ety001 ety001 commented Jul 14, 2026

Copy link
Copy Markdown
Member

Problem

rpc.Validate decoded the signed params into []interface{}, which rejects JSON objects. Real-world conveyor / @steemit/koa-jsonrpc clients sign object params (e.g. {"account":"foo"}), so every authenticated request fails with "failed to unmarshal params".

Root cause

The []interface{} type was copied from RpcRequest.Params in the first commit and never revisited. The JS reference (@steemit/rpc-auth validate) returns JSON.parse(jsonString), which is shape-agnostic (accepts objects, arrays, scalars — any valid JSON).

Evidence that this was not a deliberate design:

  • No commit message or code comment argues for an "arrays only" convention
  • The JS reference's own server tests (koa-jsonrpc/test/auth.ts) sign with object params exclusively
  • Every Go test only used array params, so the bug was invisible to the suite

Fix

Changed the decode target and return type from []interface{} to interface{}, matching JS JSON.parse semantics.

Breaking change for callers of rpc.Validate: return type changes from []interface{} to interface{}. The only known production caller is steemgosdk's API.VerifySignedRequest, which will be updated in a follow-up PR once this is tagged.

Tests

  • TestValidate and TestValidate_WithVerifySignedRpc updated to type-assert the returned interface{} before indexing (they previously assumed []interface{})
  • New TestValidate_ObjectParams regression test: signs and validates object params — this fails on the old code with "failed to unmarshal params", passes after the fix

Verification

  • go build ./...
  • go vet ./...
  • go test ./rpc/ -v ✅ (all pass including the new regression test)

Validate decoded the signed params into []interface{}, which rejects JSON
objects. Real-world conveyor / koa-jsonrpc clients sign object params
(e.g. {"account":"foo"}), so every authenticated request would fail
with "failed to unmarshal params".

The []interface{} type was copied from RpcRequest.Params on day one and
never revisited — the JS reference (@steemit/rpc-auth validate) returns
JSON.parse(jsonString), which is shape-agnostic (any). This change aligns
the Go side: the decode target and return type are now interface{}.

Breaking change for callers of rpc.Validate: return type changes from
[]interface{} to interface{}. The only known caller (steemgosdk
API.VerifySignedRequest) will be updated in a follow-up once this is
tagged.

Tests:
- TestValidate / TestValidate_WithVerifySignedRpc updated to type-assert
  the returned interface{} before indexing.
- New TestValidate_ObjectParams regression test signs and validates
  object params — this would have failed before the fix.
@kuny0707
kuny0707 merged commit 96075f0 into master Jul 14, 2026
3 checks passed
@ety001
ety001 deleted the fix/validate-object-params branch July 15, 2026 00:09
ety001 added a commit to steemit/steemgosdk that referenced this pull request Jul 15, 2026
…pe (#12)

steemutil v0.0.26 (PR steemit/steemutil#14) changed rpc.Validate's return
type from []interface{} to interface{} to accept JSON object params (the
shape conveyor/koa-jsonrpc clients actually sign). This is the follow-up:

- go.mod: require steemutil v0.0.26
- api/verify.go: VerifySignedRequest return type []interface{} -> interface{}
  to match. Updated doc comment to note the shape-agnostic semantics.
- api/verify_test.go: TestVerifySignedRequest_Success now type-asserts the
  returned interface{} before indexing (previously assumed []interface{}).
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