lightningd: add support for filters on "rpc_command" hook.
What changed, and why it matters
This commit adds a new optional feature to Core Lightning plugins. Plugin authors can now tell the 'rpc_command' hook to only intercept specific RPC commands by name, rather than being sent every single command. This is a convenience/performance improvement, not a security fix or vulnerability.
No security action required. This is a feature addition. Review plugin documentation if you maintain a plugin that uses rpc_command to consider whether filtering is appropriate.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change replaces REGISTER_PLUGIN_HOOK with REGISTER_PLUGIN_HOOK_STRFILTER for the rpc_command hook, enabling string-based filtering on the command name. The hook call now passes c->json_cmd->name as the filter key. Documentation is updated to describe the new optional ‘filters’ array. There is no evidence of a vulnerability being patched.
Changed components
lightningd/jsonrpc.cplugin rpc_command hookInspect captured patch +9 / −7
diff --git a/doc/developers-guide/plugin-development/hooks.md b/doc/developers-guide/plugin-development/hooks.md
index ba2c53da..96f1ff1a 100644
--- a/doc/developers-guide/plugin-development/hooks.md
+++ b/doc/developers-guide/plugin-development/hooks.md
@@ -506,7 +506,8 @@ The `htlc_accepted` hook is a chained hook, i.e., multiple plugins can register
### `rpc_command`
-The `rpc_command` hook allows a plugin to take over any RPC command. It sends the received JSON-RPC request (for any method!) to the registered plugin,
+The `rpc_command` hook allows a plugin to take over any RPC command. It sends the received JSON-RPC request to the registered plugin. You can optionally specify a "filters" array, containing the command names you want to intercept: without this, all commands will be sent to this hook.
+
```json
{
diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c
index 6e2d5f7a..48f5cd75 100644
--- a/lightningd/jsonrpc.c
+++ b/lightningd/jsonrpc.c
@@ -1003,11 +1003,11 @@ log_error_and_skip:
return true;
}
-REGISTER_PLUGIN_HOOK(rpc_command,
- rpc_command_hook_callback,
- rpc_command_hook_final,
- rpc_command_hook_serialize,
- struct rpc_command_hook_payload *);
+REGISTER_PLUGIN_HOOK_STRFILTER(rpc_command,
+ rpc_command_hook_callback,
+ rpc_command_hook_final,
+ rpc_command_hook_serialize,
+ struct rpc_command_hook_payload *);
/* We return struct command_result so command_fail return value has a natural
* sink; we don't actually use the result. */
@@ -1124,7 +1124,8 @@ parse_request(struct json_connection *jcon,
trace_span_start("lightningd/jsonrpc", &c);
trace_span_tag(&c, "method", c->json_cmd->name);
- completed = plugin_hook_call_rpc_command(jcon->ld, c->id, rpc_hook);
+ /* They can filter by command name */
+ completed = plugin_hook_call_rpc_command(jcon->ld, c->json_cmd->name, c->id, rpc_hook);
trace_span_end(&c);
/* If it's deferred, mark it (otherwise, it's completed) */
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.