tests: added *non-developer mode* test for invalid filtering
What changed, and why it matters
This commit adds a test for a crash that only happens when Core Lightning runs in normal (non-developer) mode. A user sending a malformed JSON filter through the command-line tool could cause the node to crash because a logging function expects data that isn't set in non-dev mode. The test confirms the crash and the expected error message.
Locate and review the associated fix commit for the `command_log()` / `cmd->json_cmd` crash path, ensure it is merged, and consider backporting to stable branches. The test itself should be run in CI against non-developer builds to prevent regression.
Security signals we found
Denial-of-service vector via malformed RPC filter input
Crash only reproducible in production (non-developer) configuration
Use-after-null or null-deref pattern in `command_log()` due to unpopulated `cmd->json_cmd`
Regression test added for a previously unhandled error path
Evidence from the diff
The new test test_filter_with_invalid_json exercises a bug where invalid JSON filtering crashes the daemon in non-developer mode. In developer mode, the invalid token is printed directly, avoiding the problematic path. In non-developer mode, command_log() is invoked and dereferences cmd->json_cmd, which is not populated, leading to a crash. The test starts a node with all dev* options stripped, runs lightning-cli with -k wait and filter parameters, and asserts the process exits with code 1 and emits ‘filter: Expected object: invalid token’. The commit only adds the regression test; it does not contain the actual fix.
Changed components
tests/test_misc.pyRPC command/filter handlingcommand_log() logging pathlightning-cli filter parsingInspect captured patch +24 / −0
diff --git a/tests/test_misc.py b/tests/test_misc.py
index e17d4935..e159b1c4 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -5042,3 +5042,27 @@ def test_zero_locktime_blocks(node_factory, bitcoind):
l2.rpc.close(l3.info['id'])
bitcoind.generate_block(1, wait_for_mempool=2)
sync_blockheight(bitcoind, [l1, l2, l3])
+
+
+def test_filter_with_invalid_json(node_factory):
+ # This crashes only in *non-developer mode*: it uses command_log()
+ # in that case (since it doesn't print the invalid token in
+ # non-dev mode), and that expects cmd->json_cmd to be populated!`
+ l1 = node_factory.get_node(start=False)
+ l1.daemon.early_opts = []
+ l1.daemon.opts = {k: v for k, v in l1.daemon.opts.items() if not k.startswith('dev')}
+ l1.start()
+
+ out = subprocess.run(['cli/lightning-cli',
+ '--network={}'.format(TEST_NETWORK),
+ '--lightning-dir={}'
+ .format(l1.daemon.lightning_dir),
+ '-l', '1',
+ '-k',
+ 'wait',
+ 'subsystem=invoices',
+ 'indexname=created',
+ 'nextvalue=0'],
+ stdout=subprocess.PIPE)
+ assert 'filter: Expected object: invalid token' in out.stdout.decode('utf-8')
+ assert out.returncode == 1
Why this scored 42/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.