[fix] callback url validation (#2959)

This commit is contained in:
Vlad Stan
2025-02-13 15:11:46 +02:00
committed by GitHub
parent b76d8b5458
commit bfa23568e3
14 changed files with 139 additions and 5 deletions
+10
View File
@@ -5,6 +5,7 @@ from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Any, Optional, Type
from urllib import request
from urllib.parse import urlparse
import jinja2
import jwt
@@ -272,6 +273,15 @@ def is_lnbits_version_ok(
return True
def check_callback_url(url: str):
netloc = urlparse(url).netloc
for rule in settings.lnbits_callback_url_rules:
if re.match(rule, netloc) is None:
raise ValueError(
f"Callback not allowed. URL: {url}. Netloc: {netloc}. Rule: {rule}"
)
def download_url(url, save_path):
with request.urlopen(url, timeout=60) as dl_file:
with open(save_path, "wb") as out_file: