Serialize experimental TLV records in unsigned invoice requests
What changed, and why it matters
This commit fixes a bug in how unsigned invoice requests were serialized before being signed. The code previously left out experimental extra data, meaning a signer reviewing the request would not see everything their signature would later cover. A malicious offer could hide data in that experimental space, getting a valid signature on content the signer never reviewed. The fix makes the unsigned serialization include both the normal and experimental bytes.
Review and merge the fix; ensure the analogous `UnsignedBolt12Invoice` fix in the following commit is also merged. HSM and custom signers should upgrade to a release containing this patch and verify that their signer serialization matches the full tagged hash input.
Security signals we found
Signature commits to data not shown to signer (truncated serialization)
Experimental/unknown odd TLV records omitted from pre-signature review
Potential HSM/custom signer policy bypass via hidden extensions
Round-trip test added to detect serialization/hash mismatch
Evidence from the diff
The Writeable implementation for UnsignedInvoiceRequest in lightning/src/offers/invoice_request.rs previously wrote only self.bytes, omitting self.experimental_bytes. However, tagged_hash and sign both commit to experimental_bytes, and the final signed InvoiceRequest appends them. This created a signature-over-unreviewed-data issue for custom/HSM signers that serialize &UnsignedInvoiceRequest via SignInvoiceRequestFn. The patch adds WithoutLength(&self.experimental_bytes).write(writer) and adds a round-trip test verifying that re-parsing the serialized unsigned request preserves the tagged_hash.
Changed components
lightning/src/offers/invoice_request.rsUnsignedInvoiceRequest::writeSignInvoiceRequestFn signer callback pathInspect captured patch +12 / −1
### lightning/src/offers/invoice_request.rs
@@ -1235,7 +1235,8 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
impl Writeable for UnsignedInvoiceRequest {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
- WithoutLength(&self.bytes).write(writer)
+ WithoutLength(&self.bytes).write(writer)?;
+ WithoutLength(&self.experimental_bytes).write(writer)
}
}
@@ -2970,6 +2971,16 @@ mod tests {
unsigned_invoice_request.tagged_hash =
TaggedHash::from_tlv_stream(SIGNATURE_TAG, tlv_stream);
+ let mut encoded_invoice_request = Vec::new();
+ unsigned_invoice_request.write(&mut encoded_invoice_request).unwrap();
+
+ match UnsignedInvoiceRequest::try_from(encoded_invoice_request) {
+ Ok(reparsed) => {
+ assert_eq!(reparsed.tagged_hash, unsigned_invoice_request.tagged_hash)
+ },
+ Err(e) => panic!("error parsing invoice_request: {:?}", e),
+ }
+
let keys = payer_keys.unwrap();
let invoice_request = unsigned_invoice_request
.sign(|message: &UnsignedInvoiceRequest| {Why this scored 72/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.