libplugin: json_id: guard against weird prefixes
What changed, and why it matters
This commit tightens a safety check in Core Lightning's plugin library. When a plugin sends a JSON-RPC request, it builds an internal ID from a method name and a prefix. The code already replaced the method name with a safe placeholder if it contained unusual characters that would need escaping. Now it does the same for the prefix. If either field had weird characters, the generated ID could be escaped differently than expected, and the plugin might fail to match the reply to the right outgoing request. The patch is a small, defensive hardening change.
Treat as a low-risk hardening fix. Review whether any caller passes a user-controlled or untrusted prefix, and consider whether json_escape_needed() is sufficient to prevent all ID-mismatch edge cases. No urgent action required.
Security signals we found
Hardening of request/response correlation ID generation
Potential mismatch between outgoing JSON-RPC id and incoming reply id if escaping occurs
Defensive validation of plugin-supplied strings before use in protocol identifiers
Evidence from the diff
In plugins/libplugin.c, json_id() constructs a request correlation ID as prefix/plugin->id:method#next_outreq_id. Previously only method was checked with json_escape_needed(); if true, method was replaced with “!weird!”. The commit adds the same check for prefix. The concern is that non-printable or otherwise JSON-escapable characters in either field would cause the ID string to be escaped, breaking exact-string matching when the reply arrives. The fix is minimal (+2/-1) and does not change behavior for normal inputs.
Changed components
plugins/libplugin.cjson_id() helperplugin JSON-RPC outgoing request ID generationInspect captured patch +2 / −1
diff --git a/plugins/libplugin.c b/plugins/libplugin.c
index d720979c..f7ee83dd 100644
--- a/plugins/libplugin.c
+++ b/plugins/libplugin.c
@@ -344,7 +344,8 @@ static const char *json_id(const tal_t *ctx, struct plugin *plugin,
const char *method, const char *prefix)
{
/* Don't create weird IDs, they will get escaped and we won't match the reply. */
- if (json_escape_needed(method, strlen(method)))
+ if (json_escape_needed(method, strlen(method)) ||
+ json_escape_needed(prefix, strlen(prefix)))
method = "!weird!";
return tal_fmt(ctx, "%s/%s:%s#%"PRIu64,
prefix, plugin->id, method, plugin->next_outreq_id++);
Why this scored 38/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.