Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check description_hash only if defined #735

Closed
wants to merge 1 commit into from

Conversation

jsarenik
Copy link

Link this PR to an issue

Fixes #726

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Describe the changes you have made in this PR -

Check if the description_hash field is defined before checking it's content equals to the manually assembled one.

How Has This Been Tested?

See #726. It would be repetitive to write it here again.

Checklist:

  • My code follows the style guidelines of this project and performed a self-review of my own code
  • New and existing tests pass locally with my changes
  • I checked if I need to make corresponding changes to the documentation (and made those changes if needed)

@@ -106,7 +106,8 @@ const lnurl = {
console.error();
}
switch (true) {
case paymentRequestDetails.description_hash !== metadataHash: // LN WALLET Verifies that h tag (description_hash) in provided invoice is a hash of metadata string converted to byte array in UTF-8 encoding
case paymentRequestDetails.description_hash &&
paymentRequestDetails.description_hash !== metadataHash: // LN WALLET Verifies that h tag (description_hash) in provided invoice is a hash of metadata string converted to byte array in UTF-8 encoding
Copy link
Contributor

@escapedcat escapedcat Mar 24, 2022

Choose a reason for hiding this comment

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

Does this work as well?

case paymentRequestDetails?.description_hash !== metadataHash:

Copy link
Author

Choose a reason for hiding this comment

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

It works when description_hash is set. See #726 — all LND-made I saw invoices contain description_hash and work well with Alby even without this change.

@bumi
Copy link
Collaborator

bumi commented Mar 24, 2022

I think the LNURL spec defines that the description_hash MUST be defined and payments must be rejected if false. Or am I wrong there?

@jsarenik
Copy link
Author

@bumi description_hash is optional and correctly defined as such in https://github.com/getAlby/lightning-browser-extension/blob/master/src/declarations.d.ts#L6

@bumi
Copy link
Collaborator

bumi commented Mar 24, 2022

It's optional in the payment request but I think the LNURL spec requires it: https://github.com/fiatjaf/lnurl-rfc/blob/legacy/lnurl-pay.md see 5. (edit: new rfc link: https://github.com/fiatjaf/lnurl-rfc/blob/luds/06.md#lud-06-payrequest-base-spec)

the wallet will call the service and get a Lightning invoice specific for that payment, containing a hash of the metadata as its h tag (description_hash) and proceed to pay the invoice if it matches the expected amount and hash.

@jsarenik
Copy link
Author

jsarenik commented Mar 24, 2022

@fiatjaf Please comment.

@jsarenik
Copy link
Author

@bumi Do you think this change in C-Lightning would help? ElementsProject/lightning#5128

@fiatjaf
Copy link
Contributor

fiatjaf commented Mar 24, 2022

description_hash is necessary and must be enforced. Not checking for the description_hash is akin to not checking signatures, it's a vulnerability and a bug.

@jsarenik
Copy link
Author

Closing this. I came to it totally unaware of ElementsProject/lightning#5121

Yes, it needs to be fixed in c-lightning. Thank you @bumi for your patience while I took time to understand what's going on here.

@jsarenik jsarenik closed this Mar 25, 2022
@jsarenik jsarenik deleted the jsn/opt_description_hash branch March 25, 2022 08:56
@bumi
Copy link
Collaborator

bumi commented Mar 25, 2022

thanks for reporting, happy we found and learned something.

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.

Invalid invoice (LNURL invoice check rejects invalid LNURL invoice)
4 participants