Skip to content

btcpayserver: the clightning backend grants BTCPay full lightningd RPC over the unix socket #87

Open

Description

@ostermayer

Problem

With services.btcpayserver.lightningBackend = "clightning", BTCPay Server talks to lightningd over the unix socket (modules/btcpayserver.nix line 216: btclightning=type=clightning;server=unix:///.../lightning-rpc). The socket is rpc-file-mode=0660, and btcpayserver joins clightning's group for it (line 271). The socket has no command restriction. So the btcpayserver process can call every lightningd RPC: withdraw, pay, fundchannel, close, dev-* if enabled.

BTCPay Server is a web application. It's often exposed to the internet, by design, and its web UI can install plugins at runtime. A bug in BTCPay, a malicious plugin, or a stolen admin session therefore gives full control of the lightningd wallet. The lnd backend is in a better position: btcpayserver.nix mints a custom macaroon with a permission list for it (services.lnd.macaroons.btcpayserver).

What would narrow it

  • Connect BTCPay to clightning through clnrest with a rune that lists only the methods BTCPay needs (invoice, listinvoices, waitinvoice, pay for refunds if used, getinfo). BTCPay Server supports a clnrest/rune connection string in recent versions. This needs a check against the pinned version.
  • If the unix socket must stay, document in docs/services.md that this backend grants BTCPay full control of the lightningd wallet, so operators can choose lnd with the restricted macaroon when BTCPay is public.

How found

LLM review (Kimi K3 max, confirmed by GLM 5.3 max) flagged this. I verified it against the code. Severity: medium to high, depends on the exposure of the BTCPay web UI.

Activity

  1. added
    area: modules
    type: security
    on Oct 23, 2026
  2. ostermayer commented on Nov 16, 2026

    @ostermayer
    CollaboratorAuthor

    I checked BTCPay Server's Lightning library. BTCPay Server 2.4.7 uses BTCPayServer.Lightning 1.7.14. Its Core Lightning client connects only through JSON-RPC over the lightning-rpc socket or TCP. It has no clnrest client and can't send a rune, and its master branch is the same today. So the clnrest idea above doesn't work with the pinned version.

    #274 documents the access, so operators can choose lnd when BTCPay Server is public.

    I believe there are two ways to restrict it.

    • Put a small proxy in front of lightning-rpc that passes only the methods BTCPay Server needs. Receiving payments needs invoice, listinvoices, waitanyinvoice, getinfo and delinvoice. The Lightning node page and payouts need more, including xpay.
    • Add clnrest and rune support to BTCPayServer.Lightning upstream. Then bitcoinix can connect BTCPay Server through clnrest with a restricted rune.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: modulestype: security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions