diff options
| author | Adam Soltys <[email protected]> | 2026-11-13 16:11:02 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-13 16:11:02 -0700 |
| commit | b8b409910f71976959135b336b409c4923cf4c87 (patch) | |
| tree | 21115643c3bed3c967a9bdc2fe1c75fa9cdfa07d /test | |
| parent | 589519f2556b2d434ed23f26c705df73b6149d7c (diff) | |
| download | coinos-server-b8b409910f71976959135b336b409c4923cf4c87.tar.gz coinos-server-b8b409910f71976959135b336b409c4923cf4c87.zip | |
lnurl: fetch user-supplied URLs through the SSRF guard, relay only protocol fields
Lightning address sends (pay() and POST /send/<lnaddr>) now validate the
name and domain and fetch through safeGot instead of plain got. Zap receipt
relays from the zap request must resolve to public hosts. The LNURL decode
and proxy routes return only LNURL protocol fields instead of whatever JSON
the upstream sent, and the proxy logs failures rate-limited with a generic
error to the client. Also blocks the 172.42.0.0/16 docker range.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
| -rw-r--r-- | test/lnurl-payload.test.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/lnurl-payload.test.ts b/test/lnurl-payload.test.ts new file mode 100644 index 00000000..01d1da9b --- /dev/null +++ b/test/lnurl-payload.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, test } from "bun:test"; +import { bech32 } from "bech32"; +import { lnurlPayload } from "../lib/lnurl-payload"; +import { safeGot } from "../lib/safe-fetch"; +const pay = { tag: "payRequest", callback: "https://example.com/pay", minSendable: 1000, maxSendable: 2000, metadata: '[["text/plain","coffee"]]' }; +describe("LNURL response boundary", () => { + test("keeps supported pay fields and strips unrelated data", () => { + expect(lnurlPayload({ ...pay, secret: "internal data", commentAllowed: 100 })).toEqual({ ...pay, commentAllowed: 100 }); + }); + test("rejects unrelated and malformed JSON payloads", () => { + for (const v of [null, [], "hello", { version: "docker" }, { ...pay, minSendable: -1 }, { ...pay, maxSendable: 1 }, { ...pay, metadata: "{}" }, { ...pay, callback: "file:///etc/passwd" }, { ...pay, metadata: '[["image/png;base64","abc"]]' }]) + expect(() => lnurlPayload(v)).toThrow(); + }); + test("withdrawal and status responses expose only protocol fields", () => { + const w = { tag: "withdrawRequest", callback: "https://example.com/withdraw", k1: "challenge", defaultDescription: "withdraw", minWithdrawable: 0, maxWithdrawable: 1000 }; + expect(lnurlPayload({ ...w, secret: "hidden" })).toEqual(w); + expect(lnurlPayload({ status: "OK", secret: "hidden" })).toEqual({ status: "OK" }); + expect(lnurlPayload({ status: "ERROR", reason: "sensitive upstream error", secret: "hidden" }).reason).toBe("LNURL service returned an error"); + }); + test("requires a checksummed invoice and strips extras", () => { + expect(() => lnurlPayload({ pr: "not an invoice", routes: [] })).toThrow(); + const pr = bech32.encode("lnbc10n", Array(120).fill(0), 20000); + expect(lnurlPayload({ pr, routes: [], secret: "hidden", successAction: { tag: "message", message: "thanks", secret: "hidden" } })).toEqual({ pr, routes: [], successAction: { tag: "message", message: "thanks" } }); + }); + test("blocks internal literal targets before fetching", async () => { + for (const url of ["http://172.42.0.13:3119/health", "http://127.0.0.1", "http://169.254.169.254", "http://10.1.2.3", "http://[::1]", "http://[::ffff:127.0.0.1]", "file:///etc/passwd"]) + await expect(safeGot(url)).rejects.toThrow(); + }); +}); |
