Which package(s) are affected?
@aws-blocks/core
Describe the bug
parseRpcRequest() accepts primitive JSON-RPC params values even though JSON-RPC 2.0 requires params, when present, to be a structured value (an array or object).
The parser currently uses:
args: Array.isArray(parsed.params)
? parsed.params
: Object.values(parsed.params ?? {}),
As a result:
params: "abc" is accepted as args: ["a", "b", "c"]
params: 42 is accepted as args: []
params: true is accepted as args: []
params: null is accepted as args: []
This can turn a malformed request from a hand-written HTTP or generated native client into a valid method invocation with unexpected arguments. RpcErrorCode.InvalidParams (-32602) is already defined, but no parser path currently emits it.
Expected behavior
- Array
params remain positional arguments.
- Object
params remain named arguments, using the existing value-order behavior.
- Omitted
params continue to mean no arguments.
- Primitive or
null params return a JSON-RPC error response with code -32602 and preserve the request id.
Reproduction steps
On current main (a1de3b8), call:
parseRpcRequest(JSON.stringify({
jsonrpc: "2.0",
method: "api.echo",
params: "abc",
id: 1,
}));
Actual result:
{
"ok": true,
"request": {
"apiNamespace": "api",
"method": "echo",
"args": ["a", "b", "c"],
"id": 1
}
}
The same request with params: 42, true, or null is also accepted with an empty args array.
Suggested fix
Validate params before converting it to arguments. If the property is present, require an array or non-null object; otherwise return RpcErrorCode.InvalidParams with a structured InvalidParams error name. Add focused unit tests covering accepted array/object/omitted values and rejected primitive/null values.
Additional context
I searched existing open and closed issues and pull requests for InvalidParams, parseRpcRequest, and JSON-RPC parameter validation and did not find an existing report or implementation.
Which package(s) are affected?
@aws-blocks/coreDescribe the bug
parseRpcRequest()accepts primitive JSON-RPCparamsvalues even though JSON-RPC 2.0 requiresparams, when present, to be a structured value (an array or object).The parser currently uses:
As a result:
params: "abc"is accepted asargs: ["a", "b", "c"]params: 42is accepted asargs: []params: trueis accepted asargs: []params: nullis accepted asargs: []This can turn a malformed request from a hand-written HTTP or generated native client into a valid method invocation with unexpected arguments.
RpcErrorCode.InvalidParams(-32602) is already defined, but no parser path currently emits it.Expected behavior
paramsremain positional arguments.paramsremain named arguments, using the existing value-order behavior.paramscontinue to mean no arguments.nullparamsreturn a JSON-RPC error response with code-32602and preserve the request id.Reproduction steps
On current
main(a1de3b8), call:Actual result:
{ "ok": true, "request": { "apiNamespace": "api", "method": "echo", "args": ["a", "b", "c"], "id": 1 } }The same request with
params: 42,true, ornullis also accepted with an emptyargsarray.Suggested fix
Validate
paramsbefore converting it to arguments. If the property is present, require an array or non-null object; otherwise returnRpcErrorCode.InvalidParamswith a structuredInvalidParamserror name. Add focused unit tests covering accepted array/object/omitted values and rejected primitive/null values.Additional context
I searched existing open and closed issues and pull requests for
InvalidParams,parseRpcRequest, and JSON-RPC parameter validation and did not find an existing report or implementation.