Skip to content

Warn before promoting a channel open whose outbound the automatic swap-out would take - #688

Merged
markettes merged 8 commits into
feat/simple-auto-channel-open-e2efrom
feat/auto-channel-open-swap-out-warning
Dec 2, 2026
Merged

markettes merged 8 commits into
feat/simple-auto-channel-open-e2efrom
feat/auto-channel-open-swap-out-warning

Conversation

@markettes

@markettes markettes commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Promoting a channel open recommendation on Routing Management adds the channel's capacity to the node's local balance. When that leaves the balance over the swap-out threshold by at least a weighted provider's min swap, the next automatic liquidity run swaps the new outbound back out, paying swap fees. The channel request form has warned about this since #685; the Promote button did not.

Promote now asks for confirmation in that case only, with the same wording and the capacity the operator entered. A hot wallet's existing confirmation carries the same warning. Auto mode is unchanged: no one is there to ask, so the job opens the channel as before.

The warning is #685's code moved out of ChannelRequests.razor into SwapOutWarningService, so both pages share the rule, the text and the 5 second limit on reading the node's balance. The request form behaves as it did.

@markettes
markettes added this pull request to stack #663 November 26, 2026 15:57
@markettes markettes changed the title feat/auto channel open swap out warning Warn before promoting a channel open whose outbound the automatic swap-out would take Nov 26, 2026
@markettes
markettes marked this pull request as ready for review November 26, 2026 16:00
Copilot AI balanced review requested due to automatic review settings November 26, 2026 16:00

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review — no issues found

This PR moves the swap-out warning from ChannelRequests.razor into a shared SwapOutWarningService and adds a channel-open recommendations panel on RoutingManagement.razor with Promote/Dismiss backed by ChannelOpenPromotionService, which now uses a conditional UpdateIfStatus and cancels orphaned requests on failure. I checked the security-relevant surface: the warning HTML-encodes the only attacker-adjacent string (node.Name) before it is rendered as MarkupString; GetNamesByPubKeys uses EF parameterized Contains; the Promote/Dismiss race is closed with a single conditional UPDATE; the balance read has a 5s timeout and fails closed; promote is gated on the server-side FinanceManager role check. One functional mismatch — the page's Authorize attribute lists only Superadmin,NodeManager while Promote requires FinanceManager, so a FinanceManager-only user can never reach the button — breaks the feature for legitimate users but gives an attacker nothing, so it is not reported as a finding.

Reviewed 13 files at 8385ec8. Nothing to report.

Not a guarantee — one diff, no knowledge of your threat model.

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Promotion can use a different wallet or capacity than was checked or confirmed, allowing state changes to bypass hot-wallet confirmation or create a request for an unintended amount.

4 open issues
What changed in this PR

This PR extends the channel-opening swap-out warning to Routing Management, reusing the request form’s warning logic and five-second balance-read timeout. It also adds automatic channel-opening controls, promotion safeguards, documentation, and tests.

Changes:

  • Share swap-out warnings across both pages, including hot-wallet confirmations.
  • Add recommendation management and node settings; guard promotion status updates and clean up unsuccessful requests.
  • Expand unit and end-to-end coverage, with supporting development configuration.
File Description
test/​NodeGuard.Tests/​Services/​SwapOutWarningServiceTests.cs Tests warning amounts, eligibility, unavailable balances, and HTML encoding.
test/​NodeGuard.Tests/​Services/​ChannelOpenPromotionServiceTests.cs Tests status conflicts, zero-fee policies, and dispatch failures.
test/​NodeGuard.Tests/​E2E/​LndTestClient.cs Adds fee-policy lookup and explicit-route payments.
test/​NodeGuard.Tests/​E2E/​E2ETestBase.cs Extracts reusable channel-confirmation polling.
test/​NodeGuard.Tests/​E2E/​AutoChannelOpenE2ETests.cs Exercises recommendation and automatic channel opening.
test/​NodeGuard.Tests/​Data/​Repositories/​NodeRepositoryTests.cs Tests peer-name lookup.
src/​Services/​SwapOutWarningService.cs Centralizes warning calculation and wording.
src/​Services/​ChannelOpenPromotionService.cs Guards status transitions and handles failed dispatch.
src/​Program.cs Registers the warning service.
src/​Pages/​RoutingManagement.razor Adds recommendations, controls, and promotion confirmations.
src/​Pages/​Nodes.razor Adds automatic channel-opening settings and validation.
src/​Pages/​ChannelRequests.razor Uses the shared warning service.
src/​Data/​Repositories/​NodeRepository.cs Adds batched peer-name lookup.
src/​Data/​Repositories/​Interfaces/​INodeRepository.cs Declares the name-lookup contract.
docs/​auto-channel-open.md Documents rules, configuration, lifecycle, and limitations.
docker/​e2e/​docker-compose.yml Enables automatic-opening end-to-end scenarios.
.vscode/​launch.json Enables automatic opening with development thresholds.

Review effort: Balanced

Comment thread src/Pages/RoutingManagement.razor Resolved
Comment thread src/Pages/RoutingManagement.razor Resolved
Comment thread src/Pages/RoutingManagement.razor Resolved
Comment thread src/Pages/RoutingManagement.razor Resolved
@markettes
markettes force-pushed the feat/auto-channel-open-swap-out-warning branch from 8385ec8 to e5cd41a Compare November 26, 2026 17:51

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review — no issues found

This PR extracts #685's swap-out warning into SwapOutWarningService and reuses it to add a confirmation step before promoting a channel open on Routing Management. The security-relevant surface is small: a new transient DI service that reads the node's balance, two confirmation modals, and a moved code path. I checked the exploitable angles: the modal body and warning text are HTML-encoded by ConfirmationModal (src/Shared/ConfirmationModal.razor comment and rendering confirm this), so node names in the warning cannot inject markup; the promote path retains its FinanceManager and node-ownership checks before and after the new warning fetch; the warning fetch is wrapped in _busy/finally so a slow or failing LND call cannot wedge the button, and the 5s WaitAsync bound carries over unchanged. The only defect spotted is cosmetic: ChannelRequests now passes literal <br/><br/> into the encoded Body, so the hot-wallet modal shows the tags as text — no security impact, so it is not reported.

Reviewed 6 files at e5cd41a. Nothing to report.

Not a guarantee — one diff, no knowledge of your threat model.

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes
markettes force-pushed the feat/auto-channel-open-swap-out-warning branch from e5cd41a to f141383 Compare November 27, 2026 13:45
Comment thread src/Services/SwapOutWarningService.cs Resolved

@Jossec101 Jossec101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls also include to block automated opening if threshold would be eat those channels?

@Jossec101 Jossec101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls also include to block automated opening if threshold would be eat those channels?

@markettes
markettes force-pushed the feat/auto-channel-open-swap-out-warning branch 3 times, most recently from be58330 to 7f6838c Compare November 30, 2026 15:17
@markettes
markettes requested a review from Jossec101 November 30, 2026 18:02

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review — no issues found

This PR extracts the swap-out warning from ChannelRequests.razor into a shared SwapOutWarningService, adds a confirmation modal before promoting a channel open on RoutingManagement when the automatic swap-out would take the new outbound, and makes AutoChannelOpenJob skip (fail-closed) promotion in that case. I attacked the new trust boundaries: the warning text is HTML-encoded at every render site (ConfirmationModal encodes Body; child content uses encoded @ expressions), so no XSS via node.Name; the job blocks promotion when the balance is unreadable rather than failing open; the promote path re-checks the FinanceManager role and node ownership on both entry and submit; budget and running-balance accounting in the job loop are consistent; and the new DI dependencies are registered. No exploitable defect found. The only issue observed is cosmetic: the hot-wallet modal in ChannelRequests.razor now passes literal "

" through an HTML-encoded Body, so the tags show as text — a UI nit with no security impact, not reported.

Reviewed 10 files at 1a3fd36. Nothing to report.

Not a guarantee — one diff, no knowledge of your threat model.

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes
markettes force-pushed the feat/auto-channel-open-swap-out-warning branch from 1a3fd36 to a670be5 Compare November 30, 2026 18:26

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review — no issues found

This PR extracts the swap-out warning into a shared service, adds a confirmation step before promoting a channel open whose outbound the automatic swap-out would take, and makes Auto mode skip such promotions. The security-relevant change is that FinanceManager is added to the Routing Management page's [Authorize] roles (and nav menu) to reach the Promote button — but the page exposes many other NodeManager-only mutations (routing-engine gates, auto-rebalance toggles, dismiss) that have no per-action role check, so the role grant is broader than the stated intent. No key material or signing paths are touched; the warning service itself fails closed.

Reviewed 8 files at b65d5c3. Nothing to report.

Not a guarantee — one diff, no knowledge of your threat model.

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes
markettes force-pushed the feat/auto-channel-open-swap-out-warning branch from cd4ab92 to 8a7333c Compare November 30, 2026 18:45

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review — no issues found

The PR extracts the swap-out warning into SwapOutWarningService, wires it into the Routing Management promote flow, and makes AutoChannelOpenJob leave swap-out-affected opens unpromoted. The security-relevant change is broadening RoutingManagement.razor's [Authorize] to FinanceManager: that page also carries routing-engine gate toggles that have no per-handler role check, so FinanceManagers gain capabilities the page previously withheld from them. The warning HTML is encoded by ConfirmationModal (@Body / @ChildContent string interpolation), so no XSS via node names.

Reviewed 8 files at cd4ab92. Nothing to report.

Not a guarantee — one diff, no knowledge of your threat model.

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes
markettes force-pushed the feat/auto-channel-open-swap-out-warning branch from 8a7333c to 5e33456 Compare December 1, 2026 10:05

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review

The PR extracts the swap-out warning from ChannelRequests into a shared SwapOutWarningService, adds it to the Routing Management promote flow (with confirmation modals and a capacity re-check), makes AutoChannelOpenJob decline to promote opens the automatic swap-out would reclaim (failing closed when the balance is unreadable), and opens the Routing Management page to FinanceManager. I attacked the HTML warning string (encoded everywhere it renders — ConfirmationModal.Body and <p>@_swapOutWarning</p> are both Blazor-encoded), the role widening (FinanceManager already reaches the identical routing/liquidity controls on Nodes.razor, which has no per-role gating, so nothing new is granted), the modal race (capacity is re-read and compared in PromoteRecommendationCore; _busy blocks re-entry), and the job's balance accounting (consistent). No exploitable defect found; one cosmetic regression where the <br/><br/> separator in the ChannelRequests hot-wallet modal renders literally because ConfirmationModal HTML-encodes Body.

Reviewed Lunar-Rails/NodeGuard #688 at c144c97 — 0 inline finding(s), 0 not anchorable, 1 below the posting threshold.

1 lower-severity observation(s)
  • LOW · correctness — Literal "

    " shown in hot-wallet confirmation modal (src/Pages/ChannelRequests.razor line 568)
    ConfirmationModal renders Body via @Body, which Blazor HTML-encodes (src/Shared/ConfirmationModal.razor:8,15). The PR moved the swap-out warning from ChildContent paragraphs into the Body string with a <br/><br/> separator, so an operator approving a hot-wallet channel open now sees the literal text "

    " inside the confirmation message. No injection results (the encoding is exactly what makes this safe); it only degrades the warning's readability. No attacker gain — reported as a correctness regression of a security-relevant confirmation.

    <ConfirmationModal
        @ref="_approveOperationConfirmationModal"
        Title="Are you sure?"
        OkLabel="Yes, I am sure"
        OnCancel="@ApproveOperationCloseConfirmationModal"
        OnSubmit="@ApproveOperationSubmitConfirmationModal">
        <p>You selected a hot wallet. This means that the system will automatically use the funds in it without the need of manual approval. Are you sure you want to perform this operation?</p>
        @if (_swapOutWarning != null)
        {
            <p>@_swapOutWarning</p>
        }
    </ConfirmationModal>

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes
markettes merged commit ea8e3ee into main Dec 2, 2026
6 checks passed
@markettes
markettes deleted the feat/auto-channel-open-swap-out-warning branch December 2, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants