Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required jsonrpc string propriety inside the JSON rpc method request. #4742

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,16 @@ static void replace_command(struct rpc_command_hook_payload *p,
goto fail;
}

// deprecated phase to give the possibility to all to migrate and stay safe
// from this more restrictive change.
if (!deprecated_apis) {
const jsmntok_t *jsonrpc = json_get_member(buffer, replacetok, "jsonrpc");
if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) {
bad = "jsonrpc: \"2.0\" must be specified in the request";
goto fail;
}
}

was_pending(command_exec(p->cmd->jcon, p->cmd, buffer, replacetok,
params));
return;
Expand Down Expand Up @@ -883,12 +893,24 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
json_command_malformed(jcon, "null", "No id");
return NULL;
}

if (id->type != JSMN_STRING && id->type != JSMN_PRIMITIVE) {
json_command_malformed(jcon, "null",
"Expected string/primitive for id");
return NULL;
}

// Adding a deprecated phase to make sure that all the c-lightning wrapper
// can migrate all the frameworks
if (!deprecated_apis) {
const jsmntok_t *jsonrpc = json_get_member(jcon->buffer, tok, "jsonrpc");

if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(jcon->buffer, jsonrpc, "2.0")) {
json_command_malformed(jcon, "null", "jsonrpc: \"2.0\" must be specified in the request");
return NULL;
}
}

/* Allocate the command off of the `jsonrpc` object and not
* the connection since the command may outlive `conn`. */
c = tal(jcon->ld->jsonrpc, struct command);
Expand Down