Skip to content

Commit

Permalink
Merge pull request #61 from uma-universal-money-address/fix/sanitize
Browse files Browse the repository at this point in the history
Sanitize user names when parsing lnurlp urls
  • Loading branch information
jklein24 authored Sep 21, 2024
2 parents 141cfca + e4444a4 commit 77f3adf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ data class LnurlpRequest(
} else {
""
}
val username = urlBuilder.pathSegments[3]
val usernameRegex = "^[A-Za-z0-9._$+-]+$".toRegex()
if (!username.matches(usernameRegex)) {
throw IllegalArgumentException("Invalid username. Only alphanumeric characters and ._$+- are allowed.")
}
val receiverAddress = "${urlBuilder.pathSegments[3]}@${urlBuilder.host}$port"
val vaspDomain = urlBuilder.parameters["vaspDomain"]
val nonce = urlBuilder.parameters["nonce"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ sealed interface PayRequest {
payerData,
requestedPayeeData,
comment,
invoiceUUID
)
}
}
Expand Down
10 changes: 10 additions & 0 deletions uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ class UmaTests {
assertEquals(payreq, decodedPayReq)
}

@Test
fun `test parse Lnurlp URL with invalid user`() {
val umaLnurlpQuery =
"https://example.com/.well-known/lnurlp/\$bob(?vaspDomain=example.com&nonce=123&signature=123&" +
"isSubjectToTravelRule=true&timestamp=123&umaVersion=1.0"
assertThrows<IllegalArgumentException> {
UmaProtocolHelper().parseLnurlpRequest(umaLnurlpQuery)
}
}

@Test
fun `test isUmaLnurlpQuery future-proofing`() {
val umaLnurlpQuery =
Expand Down

0 comments on commit 77f3adf

Please sign in to comment.