mirror of
https://github.com/Such-Software/xmrcheckout.git
synced 2026-12-01 12:14:11 +01:00
fix(daemon): require an operator daemon and refuse plain http to a public node
Every shipped default pointed payment detection at a third-party daemon over plain http. Whoever ran it, or anyone on the path, could fake transfers or confirmations. MONERO_DAEMON_URL is now required with no default. The API and reconciler refuse to start with a plain-http daemon on a public host; private, loopback and local names stay allowed, and remote daemons must use https. The example and README point at an operator-run node.
This commit is contained in:
+6
-4
@@ -25,10 +25,12 @@ MONERO_WALLET_RPC_PASSWORD=
|
|||||||
MONERO_WALLET_RPC_WALLET_PASSWORD=
|
MONERO_WALLET_RPC_WALLET_PASSWORD=
|
||||||
MONERO_WALLET_RPC_WALLET_DIR=/wallets
|
MONERO_WALLET_RPC_WALLET_DIR=/wallets
|
||||||
|
|
||||||
# Monero daemon
|
# Monero daemon (required). Payment detection trusts this daemon, so use one you
|
||||||
# - Default: uses a third-party daemon (low setup, external dependency)
|
# operate: the bundled `monerod` service (http://monerod:18081 with the
|
||||||
# - Local: run the bundled `monerod` service and set MONERO_DAEMON_URL=http://monerod:18081
|
# local-daemon profile) or your own node on a private network. A plain-http
|
||||||
MONERO_DAEMON_URL=http://xmr-node.cakewallet.com:18081
|
# daemon on a public host is refused at startup, because whoever runs it, or
|
||||||
|
# sits on the path, could fake payments. Use https for a remote daemon.
|
||||||
|
MONERO_DAEMON_URL=http://monerod:18081
|
||||||
|
|
||||||
# Admin panel (generate with: openssl rand -base64 32 | tr -d '=' | head -c 32)
|
# Admin panel (generate with: openssl rand -base64 32 | tr -d '=' | head -c 32)
|
||||||
ADMIN_API_KEY=
|
ADMIN_API_KEY=
|
||||||
|
|||||||
@@ -123,8 +123,12 @@ cp .env.example .env
|
|||||||
- `MONERO_DAEMON_URL` (choose one of the options below)
|
- `MONERO_DAEMON_URL` (choose one of the options below)
|
||||||
|
|
||||||
3. Choose a Monero daemon source:
|
3. Choose a Monero daemon source:
|
||||||
- **Use a third-party daemon (default):**
|
`MONERO_DAEMON_URL` is required and has no default. Payment detection trusts the daemon, so it must
|
||||||
- Leave `MONERO_DAEMON_URL` as-is (the default points at a public Monero daemon).
|
be one you operate. A plain-http daemon on a public host is refused at startup; a remote daemon must
|
||||||
|
use https.
|
||||||
|
- **Use your own node elsewhere:**
|
||||||
|
- Set `MONERO_DAEMON_URL` to your node on a private network (for example `http://10.0.0.5:18081`),
|
||||||
|
or to an https endpoint you control.
|
||||||
- **Run your own daemon via Docker Compose:**
|
- **Run your own daemon via Docker Compose:**
|
||||||
- Set `MONERO_DAEMON_URL=http://monerod:18081`
|
- Set `MONERO_DAEMON_URL=http://monerod:18081`
|
||||||
- Start the stack with the `local-daemon` profile (see step 5)
|
- Start the stack with the `local-daemon` profile (see step 5)
|
||||||
|
|||||||
@@ -42,6 +42,44 @@ MONERO_WALLET_RPC_USER = os.getenv("MONERO_WALLET_RPC_USER", "")
|
|||||||
MONERO_WALLET_RPC_PASSWORD = os.getenv("MONERO_WALLET_RPC_PASSWORD", "")
|
MONERO_WALLET_RPC_PASSWORD = os.getenv("MONERO_WALLET_RPC_PASSWORD", "")
|
||||||
MONERO_WALLET_RPC_WALLET_PASSWORD = os.getenv("MONERO_WALLET_RPC_WALLET_PASSWORD", "")
|
MONERO_WALLET_RPC_WALLET_PASSWORD = os.getenv("MONERO_WALLET_RPC_WALLET_PASSWORD", "")
|
||||||
MONERO_DAEMON_URL = os.getenv("MONERO_DAEMON_URL")
|
MONERO_DAEMON_URL = os.getenv("MONERO_DAEMON_URL")
|
||||||
|
|
||||||
|
|
||||||
|
def check_daemon_url(url: str | None) -> None:
|
||||||
|
"""Refuse a plain-http daemon on a public host.
|
||||||
|
|
||||||
|
Payment detection trusts the daemon. Over plain http to a host on the
|
||||||
|
internet, the operator of that host or anyone on the path can fake
|
||||||
|
transfers or confirmations. http is accepted for loopback, private and
|
||||||
|
link-local addresses and for single-label or local-only names (Docker
|
||||||
|
service names such as `monerod`); anything else must use https.
|
||||||
|
"""
|
||||||
|
if not url:
|
||||||
|
return
|
||||||
|
from ipaddress import ip_address
|
||||||
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
|
parts = urlsplit(url if "://" in url else f"http://{url}")
|
||||||
|
if parts.scheme == "https":
|
||||||
|
return
|
||||||
|
host = (parts.hostname or "").lower().rstrip(".")
|
||||||
|
try:
|
||||||
|
address = ip_address(host)
|
||||||
|
except ValueError:
|
||||||
|
local = (
|
||||||
|
"." not in host
|
||||||
|
or host == "localhost"
|
||||||
|
or host.endswith((".local", ".lan", ".internal", ".home.arpa"))
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
local = address.is_private or address.is_loopback or address.is_link_local
|
||||||
|
if not local:
|
||||||
|
raise RuntimeError(
|
||||||
|
"MONERO_DAEMON_URL uses plain http to a public host; use your own daemon on a "
|
||||||
|
"private network or an https endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
check_daemon_url(MONERO_DAEMON_URL)
|
||||||
MONERO_WALLET_RPC_WALLET_DIR = os.getenv("MONERO_WALLET_RPC_WALLET_DIR", "")
|
MONERO_WALLET_RPC_WALLET_DIR = os.getenv("MONERO_WALLET_RPC_WALLET_DIR", "")
|
||||||
FOUNDER_PAYMENT_ADDRESS = os.getenv("FOUNDER_PAYMENT_ADDRESS", "")
|
FOUNDER_PAYMENT_ADDRESS = os.getenv("FOUNDER_PAYMENT_ADDRESS", "")
|
||||||
FOUNDER_VIEW_KEY = os.getenv("FOUNDER_VIEW_KEY", "")
|
FOUNDER_VIEW_KEY = os.getenv("FOUNDER_VIEW_KEY", "")
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from app.config import check_daemon_url
|
||||||
|
|
||||||
|
|
||||||
|
class DaemonUrlTests(unittest.TestCase):
|
||||||
|
def test_a_plain_http_public_daemon_is_refused(self):
|
||||||
|
for url in [
|
||||||
|
"http://xmr-node.cakewallet.com:18081",
|
||||||
|
"http://node.example.org:18081",
|
||||||
|
"http://93.184.216.34:18081",
|
||||||
|
"node.example.org:18081",
|
||||||
|
]:
|
||||||
|
with self.subTest(url=url), self.assertRaises(RuntimeError):
|
||||||
|
check_daemon_url(url)
|
||||||
|
|
||||||
|
def test_own_daemons_are_accepted(self):
|
||||||
|
for url in [
|
||||||
|
"http://monerod:18081",
|
||||||
|
"http://127.0.0.1:18081",
|
||||||
|
"http://192.168.1.20:18081",
|
||||||
|
"http://10.0.0.5:18081",
|
||||||
|
"http://host.docker.internal:18091",
|
||||||
|
"https://node.example.org:18089",
|
||||||
|
None,
|
||||||
|
]:
|
||||||
|
with self.subTest(url=url):
|
||||||
|
check_daemon_url(url)
|
||||||
|
|
||||||
|
|
||||||
|
class ShippedDefaultTests(unittest.TestCase):
|
||||||
|
def test_no_shipped_file_defaults_to_a_plain_http_public_daemon(self):
|
||||||
|
import pathlib
|
||||||
|
import re
|
||||||
|
|
||||||
|
root = pathlib.Path(__file__).resolve().parents[2]
|
||||||
|
pattern = re.compile(r"MONERO_DAEMON_URL(?::-|=)(http://[^}\s\"]+)")
|
||||||
|
for name in ["docker-compose.yml", ".env.example", "api/.env.example"]:
|
||||||
|
path = root / name
|
||||||
|
if not path.exists():
|
||||||
|
continue
|
||||||
|
for url in pattern.findall(path.read_text()):
|
||||||
|
with self.subTest(file=name, url=url):
|
||||||
|
check_daemon_url(url)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
+5
-5
@@ -32,7 +32,7 @@ services:
|
|||||||
MONERO_WALLET_RPC_PASSWORD: ${MONERO_WALLET_RPC_PASSWORD}
|
MONERO_WALLET_RPC_PASSWORD: ${MONERO_WALLET_RPC_PASSWORD}
|
||||||
MONERO_WALLET_RPC_WALLET_PASSWORD: ${MONERO_WALLET_RPC_WALLET_PASSWORD}
|
MONERO_WALLET_RPC_WALLET_PASSWORD: ${MONERO_WALLET_RPC_WALLET_PASSWORD}
|
||||||
MONERO_WALLET_RPC_WALLET_DIR: ${MONERO_WALLET_RPC_WALLET_DIR:-/wallets}
|
MONERO_WALLET_RPC_WALLET_DIR: ${MONERO_WALLET_RPC_WALLET_DIR:-/wallets}
|
||||||
MONERO_DAEMON_URL: ${MONERO_DAEMON_URL:-http://xmr-node.cakewallet.com:18081}
|
MONERO_DAEMON_URL: ${MONERO_DAEMON_URL:?set MONERO_DAEMON_URL in .env}
|
||||||
GUNICORN_WORKERS: ${GUNICORN_WORKERS:-5}
|
GUNICORN_WORKERS: ${GUNICORN_WORKERS:-5}
|
||||||
volumes:
|
volumes:
|
||||||
- ./qr:/qr
|
- ./qr:/qr
|
||||||
@@ -55,7 +55,7 @@ services:
|
|||||||
MONERO_WALLET_RPC_PASSWORD: ${MONERO_WALLET_RPC_PASSWORD}
|
MONERO_WALLET_RPC_PASSWORD: ${MONERO_WALLET_RPC_PASSWORD}
|
||||||
MONERO_WALLET_RPC_WALLET_PASSWORD: ${MONERO_WALLET_RPC_WALLET_PASSWORD}
|
MONERO_WALLET_RPC_WALLET_PASSWORD: ${MONERO_WALLET_RPC_WALLET_PASSWORD}
|
||||||
MONERO_WALLET_RPC_WALLET_DIR: ${MONERO_WALLET_RPC_WALLET_DIR:-/wallets}
|
MONERO_WALLET_RPC_WALLET_DIR: ${MONERO_WALLET_RPC_WALLET_DIR:-/wallets}
|
||||||
MONERO_DAEMON_URL: ${MONERO_DAEMON_URL:-http://xmr-node.cakewallet.com:18081}
|
MONERO_DAEMON_URL: ${MONERO_DAEMON_URL:?set MONERO_DAEMON_URL in .env}
|
||||||
depends_on:
|
depends_on:
|
||||||
api:
|
api:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
@@ -114,7 +114,7 @@ services:
|
|||||||
"18083",
|
"18083",
|
||||||
"--confirm-external-bind",
|
"--confirm-external-bind",
|
||||||
"--daemon-address",
|
"--daemon-address",
|
||||||
"${MONERO_DAEMON_URL:-http://xmr-node.cakewallet.com:18081}",
|
"${MONERO_DAEMON_URL:?set MONERO_DAEMON_URL in .env}",
|
||||||
"--rpc-login",
|
"--rpc-login",
|
||||||
"${MONERO_WALLET_RPC_USER}:${MONERO_WALLET_RPC_PASSWORD}",
|
"${MONERO_WALLET_RPC_USER}:${MONERO_WALLET_RPC_PASSWORD}",
|
||||||
"--wallet-dir",
|
"--wallet-dir",
|
||||||
@@ -143,7 +143,7 @@ services:
|
|||||||
"18083",
|
"18083",
|
||||||
"--confirm-external-bind",
|
"--confirm-external-bind",
|
||||||
"--daemon-address",
|
"--daemon-address",
|
||||||
"${MONERO_DAEMON_URL:-http://xmr-node.cakewallet.com:18081}",
|
"${MONERO_DAEMON_URL:?set MONERO_DAEMON_URL in .env}",
|
||||||
"--rpc-login",
|
"--rpc-login",
|
||||||
"${MONERO_WALLET_RPC_USER}:${MONERO_WALLET_RPC_PASSWORD}",
|
"${MONERO_WALLET_RPC_USER}:${MONERO_WALLET_RPC_PASSWORD}",
|
||||||
"--wallet-dir",
|
"--wallet-dir",
|
||||||
@@ -172,7 +172,7 @@ services:
|
|||||||
"18083",
|
"18083",
|
||||||
"--confirm-external-bind",
|
"--confirm-external-bind",
|
||||||
"--daemon-address",
|
"--daemon-address",
|
||||||
"${MONERO_DAEMON_URL:-http://xmr-node.cakewallet.com:18081}",
|
"${MONERO_DAEMON_URL:?set MONERO_DAEMON_URL in .env}",
|
||||||
"--rpc-login",
|
"--rpc-login",
|
||||||
"${MONERO_WALLET_RPC_USER}:${MONERO_WALLET_RPC_PASSWORD}",
|
"${MONERO_WALLET_RPC_USER}:${MONERO_WALLET_RPC_PASSWORD}",
|
||||||
"--wallet-dir",
|
"--wallet-dir",
|
||||||
|
|||||||
Reference in New Issue
Block a user