Skip to content

Commit 3342747

Browse files
authored
Sanitize the username when parsing (#63)
* Sanitize the username when parsing * fix regex
1 parent 5898e1e commit 3342747

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

uma/uma.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
22
import json
33
import random
4+
import re
45
from dataclasses import replace
56
from datetime import datetime, timezone
67
from math import floor
@@ -28,6 +29,11 @@
2829
CounterpartyDataOptions,
2930
)
3031
from uma.protocol.currency import Currency
32+
from uma.protocol.invoice import (
33+
Invoice,
34+
InvoiceCounterpartyDataOptions,
35+
InvoiceCurrency,
36+
)
3137
from uma.protocol.kyc_status import KycStatus
3238
from uma.protocol.lnurlp_request import LnurlpRequest
3339
from uma.protocol.lnurlp_response import LnurlComplianceResponse, LnurlpResponse
@@ -45,11 +51,6 @@
4551
)
4652
from uma.protocol.post_tx_callback import PostTransactionCallback, UtxoWithAmount
4753
from uma.protocol.pubkey_response import PubkeyResponse
48-
from uma.protocol.invoice import (
49-
Invoice,
50-
InvoiceCounterpartyDataOptions,
51-
InvoiceCurrency,
52-
)
5354
from uma.public_key_cache import IPublicKeyCache
5455
from uma.type_utils import none_throws
5556
from uma.uma_invoice_creator import IUmaInvoiceCreator
@@ -373,6 +374,9 @@ def parse_lnurlp_request(url: str) -> LnurlpRequest:
373374
if len(paths) != 4 or paths[1] != ".well-known" or paths[2] != "lnurlp":
374375
raise InvalidRequestException("Invalid request path.")
375376

377+
if not re.match(r"^[\$a-zA-Z0-9@._\-\+]+$", paths[3]):
378+
raise InvalidRequestException("Invalid characters in receiver address.")
379+
376380
receiver_address = paths[3] + "@" + parsed_url.netloc
377381
is_subject_to_travel_rule = (
378382
query.get("isSubjectToTravelRule", [""])[0].lower() == "true"

0 commit comments

Comments
 (0)