lnbits / lnurl

LNURL implementation for Python.
https://pypi.org/project/lnurl
MIT License
64 stars 19 forks source link

Valid URL does not pass validation #7

Closed damanic closed 3 years ago

damanic commented 3 years ago

Is there a good reason why the following URL does not pass validation:

https://sub.domain.net:5008/

?


Traceback (most recent call last): File "/opt/venv/lib/python3.7/site-packages/lnurl/core.py", line 24, in encode return Lnurl(_url_encode(url)) File "/opt/venv/lib/python3.7/site-packages/lnurl/types.py", line 161, in init self.url = url if url else self.get_url(bech32) File "/opt/venv/lib/python3.7/site-packages/lnurl/types.py", line 165, in get_url return parse_obj_as(Union[OnionUrl, ClearnetUrl], _lnurl_decode(bech32)) File "/opt/venv/lib/python3.7/site-packages/pydantic/tools.py", line 35, in parse_obj_as return model_type(root=obj).root File "/opt/venv/lib/python3.7/site-packages/pydantic/main.py", line 400, in init raise validation_error pydantic.error_wrappers.ValidationError: 2 validation errors for ParsingModel[Union[lnurl.types.OnionUrl, lnurl.types.ClearnetUrl]] root URL host invalid, top level domain required (type=value_error.url.host) root URL scheme not permitted (type=value_error.url.scheme; allowed_schemes={'https'})

jogc commented 3 years ago

Can't reproduce. Seems to be a pydantic issue. What version of pydantic is this?

damanic commented 3 years ago

pydantic v1.8.1 lnurl v0.3.6

I posted the URL format entered into the browser that triggers the error. If this URL format passes on your tests (not reproducible) then perhaps the URL scheme/format being passed onto lnurl is changed on route - I am using a HTTPS->TOR proxy.

I get HTTP response 426 on

https://sub.domain.net:5008/lnurlp/api/v1/links?all_wallets=

message | "LNURLs need to be delivered over a publically accessiblehttpsdomain or Tor."

If there was a log of the failed URL, or if it was included in the error msg - that would help clear this up.

jogc commented 3 years ago

@eillarra ?

eillarra commented 3 years ago

@damanic Can you provide more background? The URL is valid and it gets properly encoded:

(py-lnurl) eillarra % python
Python 3.7.7 (default, Apr  9 2020, 15:17:23) 
[Clang 11.0.3 (clang-1103.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lnurl
>>> lnurl.encode('https://sub.domain.net:5008/')
Lnurl('LNURL1DP68GURN8GHJ7UM4VGHXGMMDV95KUTNWV46R5DFSXQUZ77KU4XL', bech32=Bech32('LNURL1DP68GURN8GHJ7UM4VGHXGMMDV95KUTNWV46R5DFSXQUZ77KU4XL', hrp='lnurl', data=[13, 1, 26, 7, 8, 28, 3, 19, 7, 8, 23, 18, 30, 28, 27, 21, 12, 8, 23, 6, 8, 27, 27, 13, 12, 5, 20, 22, 28, 11, 19, 14, 12, 21, 26, 3, 20, 13, 9, 16, 6, 0, 28, 2, 30]), url=ClearnetUrl('https://sub.domain.net:5008/', scheme='https', host='sub.domain.net', tld='net', host_type='domain', port='5008', path='/'))

LNURL detects the ClearnetUrl type correctly.

My guess is there is some issue in your LNbits configuration. I remember that you have to be careful when proxying https addresses with LNbits or it is possible that LNbits is not receiving the https part correctly; so in your case, even if the address is https, internally LNbits is trying to encode a http address, hence the lnurl exception.

damanic commented 3 years ago

@eillarra

I think we can now say with some confidence that the URL I enter into my browser to access LNbits is not the exact URL being considered by LNbits internally, after it has been routed through my proxy.

Background:

Can you think of a simple method I can use to log the URL being considered by LNbits so I can confirm the exact URL string that is failing to validate. And/or point me to the method used to pull in the clients access point/url?

In the meantime I will try to generate a resuable lnurl-pay address via command line. Thanks!

eillarra commented 3 years ago

Based on the link you mentioned before, you can check here what is the URL you are trying to encode, just to be sure: https://github.com/lnbits/lnbits/blob/master/lnbits/extensions/lnurlp/models.py#L31 If you have access to the code I would start debugging there.

In the LNbits Telegram channel you will probably find somebody that had this same proxy issue before.