mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
plugin: Wrap custom notifications in a dict with additional origin
This should allow us to differentiate the origin of the notification, and further prevent plugins from spoofing native notifications.
This commit is contained in:
committed by
Rusty Russell
parent
cfb1107244
commit
62e3358a5b
@@ -453,19 +453,10 @@ static const char *plugin_notification_handle(struct plugin *plugin,
|
|||||||
methname = json_strdup(tmpctx, plugin->buffer, methtok);
|
methname = json_strdup(tmpctx, plugin->buffer, methtok);
|
||||||
|
|
||||||
if (notifications_have_topic(plugin->plugins, methname)) {
|
if (notifications_have_topic(plugin->plugins, methname)) {
|
||||||
n = tal(NULL, struct jsonrpc_notification);
|
n = jsonrpc_notification_start(NULL, methname);
|
||||||
n->method = tal_steal(n, methname);
|
json_add_string(n->stream, "origin", plugin->shortname);
|
||||||
n->stream = new_json_stream(n, NULL, NULL);
|
json_add_tok(n->stream, "payload", paramstok, plugin->buffer);
|
||||||
json_object_start(n->stream, NULL);
|
jsonrpc_notification_end(n);
|
||||||
json_add_string(n->stream, "jsonrpc", "2.0");
|
|
||||||
json_add_string(n->stream, "method", methname);
|
|
||||||
|
|
||||||
json_add_tok(n->stream, "params", paramstok, plugin->buffer);
|
|
||||||
|
|
||||||
json_object_end(n->stream); /* closes '.' */
|
|
||||||
|
|
||||||
/* We guarantee to have \n\n at end of each response. */
|
|
||||||
json_stream_append(n->stream, "\n\n", strlen("\n\n"));
|
|
||||||
|
|
||||||
plugins_notify(plugin->plugins, take(n));
|
plugins_notify(plugin->plugins, take(n));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ plugin = Plugin()
|
|||||||
|
|
||||||
|
|
||||||
@plugin.subscribe("custom")
|
@plugin.subscribe("custom")
|
||||||
def on_custom_notification(val, plugin, **kwargs):
|
def on_custom_notification(origin, payload, **kwargs):
|
||||||
plugin.log("Got a custom notification {}".format(val))
|
plugin.log("Got a custom notification {} from plugin {}".format(payload, origin))
|
||||||
|
|
||||||
|
|
||||||
@plugin.method("emit")
|
@plugin.method("emit")
|
||||||
|
|||||||
@@ -2404,7 +2404,6 @@ def test_self_disable(node_factory):
|
|||||||
l1.rpc.plugin_start(p2, selfdisable=True)
|
l1.rpc.plugin_start(p2, selfdisable=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(strict=True)
|
|
||||||
def test_custom_notification_topics(node_factory):
|
def test_custom_notification_topics(node_factory):
|
||||||
plugin = os.path.join(
|
plugin = os.path.join(
|
||||||
os.path.dirname(__file__), "plugins", "custom_notifications.py"
|
os.path.dirname(__file__), "plugins", "custom_notifications.py"
|
||||||
|
|||||||
Reference in New Issue
Block a user