lightningd: reject newlines in persistent setconfig values
What changed, and why it matters
This commit fixes a bug in Core Lightning's `setconfig` RPC command. Previously, a user or attacker who could call `setconfig` could store a configuration value containing newline characters. Because persistent settings are written into a config file line-by-line, those newlines could split one setting into multiple lines, effectively injecting extra configuration directives. The patch now rejects any persistent value containing `\n` or `\r`.
Treat this as a security fix and include it in release notes. Users running affected versions should upgrade and audit persistent config files for unexpected injected lines if they exposed `setconfig` to untrusted callers.
Security signals we found
config file injection via unsanitized persistent option values
newline/carriage-return input validation added
RPC parameter rejection with JSONRPC2_INVALID_PARAMS
transient values excluded from restriction, indicating persistent storage is the attack surface
commit message explicitly calls the issue 'config-line injection'
Evidence from the diff
The json_setconfig handler in lightningd/configs.c writes persistent option values into a configuration file. Without validation, a value containing \n or \r would be serialized across multiple lines, allowing arbitrary config-line injection on the next daemon start. The patch adds two checks: one for array-type values and one for scalar values, both returning JSONRPC2_INVALID_PARAMS if a persistent value contains newline or carriage-return characters. Transient (--transient) values are explicitly exempted from the check because they are not written to disk.
Changed components
lightningd/configs.cjson_setconfig RPC commandpersistent configuration storageInspect captured patch +12 / −0
### lightningd/configs.c
@@ -688,6 +688,13 @@ static struct command_result *json_setconfig(struct command *cmd,
vals = tal_arr(cmd, const char *, valtok->size);
json_for_each_arr(i, t, valtok) {
vals[i] = json_strdup(vals, buffer, t);
+ if (!*transient
+ && (strchr(vals[i], '\n')
+ || strchr(vals[i], '\r')))
+ return command_fail(cmd,
+ JSONRPC2_INVALID_PARAMS,
+ "%s value must not contain newlines",
+ ot->names + 2);
}
} else {
/* No val means empty array (clear all) */
@@ -740,6 +747,11 @@ static struct command_result *json_setconfig(struct command *cmd,
const struct configvar *cv;
const char *fname;
+ if (val && (strchr(val, '\n') || strchr(val, '\r')))
+ return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
+ "%s value must not contain newlines",
+ ot->names + 2);
+
cv = configvar_first(cmd->ld->configvars,
opt_names_arr(tmpctx, ot));
Why this scored 62/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.