Skip to content

Conversation

@erickcestari
Copy link
Contributor

Through differential fuzzing between C-Lightning and rust-lightning, I discovered that rust-lightning incorrectly accepts BOLT 12 offers that start with whitespace when they contain continuation characters (+).

offer: \u{b}lno1pqpzwyq2p32x2um5ypmx2cm5dae8x93pqthvwfzadd7jejes8q9lhc4rvjxd022zv5l44g6qah+\u{b}\u{b}\u{b}\u{b}82ru5rdpnpj

Expected behavior: Both implementations should reject this offer
Actual behavior:

  • C-Lightning: Correctly rejects the offer (empty result)
  • rust-lightning: Incorrectly parses and accepts the offer

This pr check that the first chunk doesn't contain whitespace characters without trimming it.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 8, 2025

👋 I see @joostjager was un-assigned.
If you'd like another reviewer assignment, please click here.

@erickcestari erickcestari force-pushed the encoded-offer-with-leading-whitespace branch from 24d25bb to cc0947a Compare August 8, 2025 14:52
@codecov
Copy link

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.94%. Comparing base (e01663a) to head (29dfc1f).
⚠️ Report is 39 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/offers/parse.rs 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3998      +/-   ##
==========================================
- Coverage   88.97%   88.94%   -0.04%     
==========================================
  Files         174      174              
  Lines      124161   124593     +432     
  Branches   124161   124593     +432     
==========================================
+ Hits       110470   110814     +344     
- Misses      11216    11285      +69     
- Partials     2475     2494      +19     
Flag Coverage Δ
fuzzing 22.18% <0.00%> (-0.47%) ⬇️
tests 88.76% <87.50%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erickcestari erickcestari force-pushed the encoded-offer-with-leading-whitespace branch from cc0947a to 45afedb Compare August 8, 2025 15:07
Found through differential fuzzing between C-Lightning and rust-lightning:
rust-lightning incorrectly accepted offers starting with whitespace when
continuation characters (+) were present, while C-Lightning correctly
rejected them per BOLT 12 specification.

- Add InvalidLeadingWhitespace error variant to Bolt12ParseError
- Validate that bech32 strings don't start with whitespace characters
- Separate validation logic for first chunk vs continuation chunks
- Add test case for leading whitespace validation
@erickcestari erickcestari force-pushed the encoded-offer-with-leading-whitespace branch from 45afedb to 29dfc1f Compare August 8, 2025 18:08
@TheBlueMatt TheBlueMatt removed the request for review from joostjager August 8, 2025 18:31
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@TheBlueMatt TheBlueMatt merged commit 192618b into lightningdevkit:main Aug 8, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants