Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/lnurl_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bitcoin::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine};
use bitcoin::secp256k1::{All, Message, Secp256k1, SecretKey};
use bitreq::Client;
use lightning::util::logger::Logger as LdkLogger;
use lightning_types::string::PrintableString;
use serde::{Deserialize, Serialize};

use crate::logger::{log_debug, log_error, Logger};
Expand Down Expand Up @@ -86,8 +87,6 @@ impl LnurlAuth {
Error::InvalidLnurl
})?;

log_debug!(self.logger, "Starting LNURL-auth process for URL: {lnurl_auth_url}");

// Parse the URL to extract domain and parameters
let url = bitreq::Url::parse(&lnurl_auth_url).map_err(|e| {
log_error!(self.logger, "Invalid LNURL-auth URL: {e}");
Expand All @@ -96,6 +95,10 @@ impl LnurlAuth {

let domain = url.base_url();

// Only log the domain, the full URL carries the k1 challenge and potentially other
// credentials.
log_debug!(self.logger, "Starting LNURL-auth process for domain: {domain}");

// Enforce HTTPS for non-localhost URLs per LNURL spec.
let is_localhost = domain == "localhost" || domain == "127.0.0.1" || domain == "[::1]";
if url.scheme() != "https" && !is_localhost {
Expand All @@ -112,7 +115,11 @@ impl LnurlAuth {
})?;

if tag != "login" {
log_error!(self.logger, "Invalid tag parameter in LNURL-auth URL: {tag}");
log_error!(
self.logger,
"Invalid tag parameter in LNURL-auth URL: {}",
PrintableString(tag)
);
return Err(Error::InvalidLnurl);
}

Expand Down Expand Up @@ -158,7 +165,11 @@ impl LnurlAuth {
Ok(())
} else {
let reason = response.reason.unwrap_or_else(|| "Unknown error".to_string());
log_error!(self.logger, "LNURL-auth authentication failed: {reason}");
log_error!(
self.logger,
"LNURL-auth authentication failed: {}",
PrintableString(&reason)
);
Err(Error::LnurlAuthFailed)
}
}
Expand Down
Loading