aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts22
1 files changed, 21 insertions, 1 deletions
diff --git a/routes/payments.ts b/routes/payments.ts
index 9cc31434..491ee3cc 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -8,6 +8,7 @@ import ln from "$lib/ln";
import { platformFee, quoteMax, quoteRoutingFee } from "$lib/lnquote";
import { err, l, quiet, shortError, suppressed, warn } from "$lib/logging";
import mqtt from "$lib/mqtt";
+import { isNotifier } from "$lib/notifier";
import {
build,
completePayment,
@@ -551,8 +552,27 @@ export default {
async confirm(req, res) {
const {
- body: { txid, wallet, type },
+ body: { wallet, type },
} = req;
+ // Canonical lowercase txid. bitcoind accepts any hex case, but the
+ // credited:/payment: dedupe keys are case-sensitive, so a mixed-case txid
+ // would re-credit an already-credited output.
+ const txid = String(req.body?.txid ?? "").toLowerCase();
+ if (!/^[0-9a-f]{64}$/.test(txid)) return res.code(400).send("invalid txid");
+ // Only our own wallet notify scripts may call this (they hit app:3119
+ // directly). Anything that came through Cloudflare or the onion carries
+ // cf-connecting-ip (set in lib/app.ts for tor) or x-forwarded-for.
+ if (req.headers["cf-connecting-ip"] || req.headers["x-forwarded-for"])
+ return res.code(403).send("forbidden");
+ // Headers alone are not enough: the UI's /post/<path> route relays to us
+ // without them. Require the TCP peer to be a node container or ourselves.
+ if (!isNotifier(req)) {
+ warn("confirm refused from", req.socket?.remoteAddress, txid, wallet);
+ return res.code(403).send("forbidden");
+ }
+ if (type !== PaymentType.bitcoin && type !== PaymentType.liquid)
+ return res.code(400).send("invalid type");
+ if (typeof wallet !== "string") return res.code(400).send("invalid wallet");
try {
const node = rpc({ ...config[type], wallet });