common: ignore proof-only fields when checking omitted markers
What changed, and why it matters
This commit fixes a validation bug in Core Lightning's handling of BOLT12 payer proofs. A payer proof is a cryptographic receipt that helps verify a payment. The bug allowed a malformed proof—one missing a required type-239 field—to be accepted as valid if it only contained a special 'omitted marker' value of 1,000,000,000. This happened because the code mistakenly treated certain proof-only fields as if they were regular invoice fields when checking whether a marker was legitimate. The fix makes the validator ignore those proof-only fields during that check, matching what another part of the code already did. A new test confirms the invalid proof is now rejected.
Review whether any other BOLT12 proof/invoice validation paths conflate proof-only fields with invoice fields. Ensure the fix is included in the next release and consider whether a security advisory is warranted if malformed proofs could lead to payment or routing issues.
Security signals we found
Validation bypass in BOLT12 payer proof omitted-marker check
Inconsistent handling of proof-only TLV range vs. existing next_field_check logic
Regression test added for rejected invalid proof
Evidence from the diff
In common/bolt12_proof.c, find_included_marker_predecessor() iterates payer_proof TLV fields to determine whether an omitted marker follows an included invoice TLV. Previously it skipped only the signature field (is_tlv_signature_field), so any field in the proof-only range 1001..999999999 was treated as an invoice TLV. Because next_marker() for that range returns 1000000000, a proof whose only omitted marker was 1000000000 would pass validation even if no type-239 field existed. The patch adds a continue for f->numtype between 1001 and 999999999, consistent with next_field_check(). The test file adds a regression case asserting that a lone 1000000000 marker with no type-239 field is rejected.
Changed components
common/bolt12_proof.ccommon/test/run-bolt12_proof_marker_jump.cInspect captured patch +29 / −2
### common/bolt12_proof.c
@@ -40,16 +40,24 @@ static bigsize_t next_marker(bigsize_t prev)
return prev + 1;
}
-/* Is there an included non-signature TLV in `pptlv` whose successor marker
+/* Is there an included invoice TLV in `pptlv` whose successor marker
* is exactly `omitted`? Used by the reader to accept a marker that follows
- * an included TLV rather than the previous marker. */
+ * an included TLV rather than the previous marker.
+ *
+ * Proof-only fields (signature range 1001..999999999, and the signature
+ * itself) are not invoice TLVs. next_marker() of anything in that gap is
+ * 1000000000, so counting them would accept a lone 1000000000 marker with
+ * no type-239 field anywhere. next_field_check() already skips this range.
+ */
static bool find_included_marker_predecessor(const struct tlv_payer_proof *pptlv,
bigsize_t omitted)
{
for (size_t i = 0; i < tal_count(pptlv->fields); i++) {
const struct tlv_field *f = &pptlv->fields[i];
if (is_tlv_signature_field(f))
continue;
+ if (f->numtype >= 1001 && f->numtype <= 999999999)
+ continue;
if (next_marker(f->numtype) == omitted)
return true;
}
### common/test/run-bolt12_proof_marker_jump.c
@@ -29,6 +29,7 @@
*/
#include "config.h"
#include <stdio.h>
+#include <string.h>
#include "../bolt12_proof.c"
#include "../bolt12_merkle.c"
#include "../bech32_util.c"
@@ -246,6 +247,24 @@ int main(int argc, char *argv[])
assert(saw_239);
assert(saw_1e9_after_239);
+ /* A lone 1000000000 marker, with no type-239 field anywhere, must
+ * not pass just because a proof-only field (signature, range
+ * 1001..999999999) has next_marker() == 1000000000. */
+ {
+ bigsize_t *only;
+ const char *bad;
+
+ only = tal_arr(tmpctx, bigsize_t, 1);
+ only[0] = 1000000000;
+ tal_free(proof->proof_omitted_tlvs);
+ proof->proof_omitted_tlvs = only;
+ bad = check_payer_proof(tmpctx, proof);
+ if (!bad)
+ fprintf(stderr, "lone 1000000000 marker was accepted\n");
+ assert(bad);
+ assert(strstr(bad, "1000000000"));
+ }
+
common_shutdown();
return 0;
}Why this scored 60/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.