Skip to content

M-H03: fix(clearnode): log correct fields on failure#647

Merged
nksazonov merged 3 commits into
fix/audit-findingsfrom
fix/audit-m-h03
Apr 7, 2026
Merged

M-H03: fix(clearnode): log correct fields on failure#647
nksazonov merged 3 commits into
fix/audit-findingsfrom
fix/audit-m-h03

Conversation

@nksazonov
Copy link
Copy Markdown
Contributor

@nksazonov nksazonov commented Apr 6, 2026

Description

RequestCreation checks asset support against the home ledger, but on the rejection path it formats the error using incomingState.EscrowLedger, which can be nil for normal channel creation requests.

    if !ok {
        c.Fail(rpc.Errorf(
            "asset %s is not supported on blockchain %d with token address %s",
            incomingState.Asset,
            incomingState.EscrowLedger.BlockchainID,
            incomingState.EscrowLedger.TokenAddress), "")
        return
    }

Because toCoreState explicitly allows EscrowLedger to be absent, a request that omits EscrowLedger and uses an unsupported home token/chain pair will trigger a nil-pointer panic before the handler can return a normal RPC error.
This panic happens before c.Fail can populate a response. The RPC server executes handlers in a separate goroutine and does not recover panics in that path, so a single malformed  channels.v1.request_creation request can terminate the entire clearnode process.
Consequently, a caller can crash the off-chain node by submitting a channel creation request with an unsupported home asset and no EscrowLedger, causing a service-wide denial of service for all users.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected diagnostic error messages to report accurate asset information when unsupported assets are encountered.
    • Enhanced system resilience by implementing panic recovery during request processing, enabling the system to gracefully handle unexpected errors and return proper error responses to clients instead of terminating.

@nksazonov nksazonov changed the base branch from main to fix/audit-findings April 6, 2026 08:30
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 6, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5474533d-82c1-458d-aac0-2c5a88eb1422

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Two independent fixes: correcting diagnostic message parameters from EscrowLedger to HomeLedger references in request creation error handling, and adding panic recovery to RPC node request handling to prevent unhandled panics from terminating execution.

Changes

Cohort / File(s) Summary
Diagnostic Message Fix
clearnode/api/channel_v1/request_creation.go
Updated error message to reference correct ledger fields (incomingState.HomeLedger.BlockchainID and incomingState.HomeLedger.TokenAddress) instead of escrow ledger fields in unsupported asset validation error.
Panic Recovery
pkg/rpc/node.go
Added inline defer/recover() wrapper around handler chain execution to catch panics, log error details with method information, and return error response instead of propagating panic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A message now points to the right ledger home,
And panics? They're caught before making us roam!
Two bugs gently fixed with surgical care,
Diagnostics and safety—a well-matched pair! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions fixing incorrect fields but does not reflect the primary objective of adding panic recovery to prevent DoS. Update the title to emphasize the main change: adding panic recovery in the handler, not just the field reference fix. Consider: 'fix(clearnode): recover from handler panics to prevent DoS' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/audit-m-h03

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/rpc/node.go`:
- Around line 315-323: The panic recover block inside the anonymous goroutine
should stop further processing so we don't marshal/send a second response or
re-panic: import runtime/debug, capture and log the stack via
wn.cfg.Logger.Error(..., "stack", string(debug.Stack())), and set a local flag
(e.g., recovered := true) or return from the outer function path so that after
calling wn.sendErrorResponse(...) the code does not continue to the ctx.Next()
result handling/marshaling; then guard the subsequent marshal/send logic (the
code using ctx.Response and marshalling) with a check that no panic was
recovered before proceeding.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf388ee5-5620-460e-aaba-84c750644a35

📥 Commits

Reviewing files that changed from the base of the PR and between e85051a and 29e161e.

📒 Files selected for processing (2)
  • clearnode/api/channel_v1/request_creation.go
  • pkg/rpc/node.go

Comment thread pkg/rpc/node.go Outdated
Comment thread pkg/rpc/node.go
@nksazonov nksazonov changed the title M-H03: fix(clearnode): recover from handler panic M-H03: fix(clearnode): log correct fields on failure Apr 7, 2026
@nksazonov nksazonov merged commit a5678a8 into fix/audit-findings Apr 7, 2026
3 checks passed
@nksazonov nksazonov deleted the fix/audit-m-h03 branch April 7, 2026 14:15
nksazonov added a commit that referenced this pull request Apr 16, 2026
H-H01: fix(contracts): disallow challenge with CLOSE or FIN_MIG intents (#631)

H-M01: fix(contracts/ChannelHub): remove transferred amount check (#636)

fix(contracts/ChannelHub): allow unblocking escrow ops after migration (#637)

M-C01: feat(contracts): add token check between states (#639)

H-L03: fix(contracts/ChannelHub): skip disputed escrow during purge (#640)

M-H04: feat(contracts/ChannelHub): purge during escrow challenge finalization, count both skip and purge (#641)

M-M02: fix(contracts): require zero allocs on close (#643)

M-C02: fix(rpc/core): apply finalize escrow deposit correctly (#644)

H-L02: fix(contracts/ChannelHub): revert on withdrawFromVault failure (#651)

M-H03: fix(clearnode): log correct fields on failure (#647)

M-C03: fix(pkg/core): disallow negative amount transitions (#645)

H-L01: fix(contracts/ChannelHub): add CH address to prevent val addition replay (#650)

M-H06(clearnode): restrict max channel challenge duration (#654)

M-M03(clearnode): revert EscrowLock on insufficient home user balance (#655)

M-M04(clearnode): support default signer even if it is not approved (#656)

M-M05(clearnode): require correct intent on FinalizeEscrowWithdrawal (#657)

M-M09: reject asset decimals exceeding its token's decimals (#659)

M-L01: return correct errors during state advancement validation (#660)

M-L03: limit number of related ids per session key state (#662)

M-I02: normalize input hex addresses (#663)

M-H01: feat(contracts/ChannelHub): restrict to one node (#649)

M-H07: fix(contracts/ChannelHub): emit stored, not arbitrary candidate state (#664)

M-I01: feat(contracts/ChannelHub): remove updateLastState flag (#665)

H-L06: fix(contracts/ChannelHub): remove payable from methods, clarify in create (#666)

H-L09: feat(contracts/ChannelEngine): add non-home migration version check (#669)

YNU-839: fix blockchain listener lifecycle (#658)

M-H09: use channel signer for all channel state node sigs (#667)

H-L07: fix(contracts/ChannelHub): restrict createChannel to non-existing channels (#668)

H-I02: docs(contracts): add a note that rebasing tokens are not supported (#670)

H-I03: fix(contracts/ChannelHub): use CIE pattern in depositToHub (#671)

M-H11: revert empty signatures on quorum verification (#672)

M-H11: reject issuance of receiver state during escrow ops (#674)

H-I01: docs(contracts): note that fee-on-transfer tokens are not supported (#675)

M-L04: docs: mention liquidity monitoring (#677)

fix(contracts/ChannelHub): fix initialize escrow deposit dos (#679)

M-H08: enforce strict transition ordering after MutualLock and EscrowLock (#680)

fix: run forge fmt (#681)

M-L05: docs(contracts): document native token deposits (#685)

fix(clearnode): resolve a set of audit findings (#686)

M-H13: feat(contract): add validateChallengeSignature, revert in SK validator (#688)
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