aboutsummaryrefslogtreecommitdiffstats
path: root/names
diff options
context:
space:
mode:
Diffstat (limited to 'names')
-rw-r--r--names/lnurl-params.js9
-rw-r--r--names/lnurl-params.test.js22
-rw-r--r--names/server.js3
3 files changed, 34 insertions, 0 deletions
diff --git a/names/lnurl-params.js b/names/lnurl-params.js
new file mode 100644
index 0000000..9b04cbc
--- /dev/null
+++ b/names/lnurl-params.js
@@ -0,0 +1,9 @@
+// Some LNURL clients (aqstr.com, 2026-12-04) append "?amount=…" to a callback
+// that already has a query, so "cb?domain=coinos.io" arrives as
+// "cb?domain=coinos.io?amount=21000": domain reads "coinos.io?amount=21000",
+// the name is unknown and the payer gets a 404.
+export function tolerantParams(search) {
+ // a literal "?" inside a query is only ever this mistake: a real one in a
+ // value arrives encoded (%3F). The first occurrence of a parameter wins.
+ return new URLSearchParams(String(search || '').replace(/^\?/, '').replace(/\?/g, '&'));
+}
diff --git a/names/lnurl-params.test.js b/names/lnurl-params.test.js
new file mode 100644
index 0000000..c198853
--- /dev/null
+++ b/names/lnurl-params.test.js
@@ -0,0 +1,22 @@
+// bun test names/lnurl-params.test.js
+import { test, expect } from 'bun:test';
+import { tolerantParams } from './lnurl-params.js';
+
+const p = (q) => tolerantParams(new URL('https://x/lnurlp/a/cb' + q).search);
+
+test('a well-formed callback is read as is', () => {
+ const r = p('?domain=coinos.io&amount=21000&comment=hi%3F');
+ expect(r.get('domain')).toBe('coinos.io');
+ expect(r.get('amount')).toBe('21000');
+ expect(r.get('comment')).toBe('hi?');
+});
+test('a second ? (amount appended with ? instead of &) still finds the name and amount', () => {
+ const r = p('?domain=coinos.io?amount=21000&nostr=%7B%7D');
+ expect(r.get('domain')).toBe('coinos.io');
+ expect(r.get('amount')).toBe('21000');
+ expect(r.get('nostr')).toBe('{}');
+});
+test("parameters already in the URL aren't overridden", () => {
+ const r = p('?amount=5000&domain=coinos.io?amount=21000');
+ expect(r.get('amount')).toBe('5000');
+});
diff --git a/names/server.js b/names/server.js
index 3e687c3..f12b08f 100644
--- a/names/server.js
+++ b/names/server.js
@@ -38,6 +38,7 @@ import { registrationIdentity } from './ownership.js';
import { openStore } from './store.js';
import { withdrawService } from './withdraw.js';
import { accountOf, accountBlockers, forgetAccount } from './forget.js';
+import { tolerantParams } from './lnurl-params.js';
import { migrateGrantRefusal } from './migrate-check.js';
const CFG = JSON.parse(readFileSync(process.env.NAMES_CONFIG
@@ -1333,6 +1334,8 @@ Bun.serve({
port: CFG.port || 8798,
async fetch(req, server) {
const url = new URL(req.url);
+ // "cb?domain=coinos.io?amount=…" from clients that append with a second "?"
+ if (/^\/(?:\.well-known\/)?lnurlp\//.test(url.pathname) && url.search.indexOf('?', 1) > 0) url.search = tolerantParams(url.search).toString();
if (req.method === 'OPTIONS') return json({});
const ip = req.headers.get('cf-connecting-ip') || req.headers.get('x-forwarded-for') || 'local';