← Back to Pull requests

cmd/commands: read full stdin for lncli unlock --stdin #10784

Closed
0xfandom closed this pull request without merging on Sep 25, 2026 03:46 UTC
View on GitHub
0xfandom 0xfandom commented on May 01, 2026 13:19 UTC
Author

Change Description

lncli unlock --stdin reads the password using bufio.ReadBytes('\n'), which terminates at the first newline byte. A wallet password that legitimately contains a newline (for example one generated from random bytes) gets silently truncated, and the unlock fails even though the same password works fine over REST/gRPC.

This switches the --stdin branch in cmd/commands/cmd_walletunlocker.go to io.ReadAll(stdin) so the password is consumed up to EOF, and trims a single trailing \n (with optional \r) so the common echo "pw" | lncli unlock --stdin invocation still works as before. Three new table-driven test cases cover an embedded newline, a stdin payload with no trailing newline, and a CRLF terminator.

Fixes #5584.

Steps to Test

1. go test ./cmd/commands/... -run TestUnlock -v — all success_stdin_* subtests pass.
2. Manual end-to-end:

   printf 'first\nsecond' > /tmp/pw
   lncli create   # set wallet password to "first\nsecond" via this file
   lncli unlock --stdin < /tmp/pw   # previously rejected, now succeeds
   

Pull Request Checklist

Testing


  • Your PR passes all CI checks.

  • Tests covering the positive and negative (error paths) are included.

  • Bug fixes contain tests triggering the bug to prevent regressions.
  • Code Style and Documentation


  • The change is not insubstantial (typo fixes not accepted).

  • Adheres to Code Documentation and Commenting guidelines, 80-char line wraps.

  • Commits follow Ideal Git Commit Structure.

  • Any new logging statements use appropriate subsystem and level.

  • Any new lncli commands have tags in proto comments.

  • Release notes added (or [skip ci] in commit message for small changes).
  • Diff: 98 lines (+93 / -5) across 3 files Reviewer: TechLateef Review duration: 211107m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.33) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.33 · 98 lines diff across 3 files
    0.33
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.78 · 5 substantive comment(s)
    0.78
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    86%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.275
    Real PR Conversation Timeline
    14 items
    github-actions[bot] github-actions[bot] commented on May 01, 2026 13:21 UTC
    Bot

    🟡 PR Severity: MEDIUM

    Automated classification | 2 files (excl. tests/generated) | 16 lines changed

    <details>
    <summary>🟡 <strong>Medium</strong> (1 file)</summary>

  • cmd/commands/cmd_walletunlocker.go - CLI client command under cmd/; classified as MEDIUM regardless of the walletunlocker name in the path
  • </details>

    <details>
    <summary>🟢 <strong>Low</strong> (1 file)</summary>

  • docs/release-notes/release-notes-0.22.0.md - Release notes documentation
  • </details>

    Analysis

    This PR modifies a CLI command file under cmd/commands/ and adds a corresponding test. Per the classification rules, files under cmd/ are always MEDIUM (CLI client code), even when the filename references a server-side package like walletunlocker. The actual server-side walletunlocker/* package is not touched. The release notes file is LOW, but the highest severity file determines the PR severity, so this is MEDIUM.

    No severity bump was triggered: only 2 non-test files changed (threshold: >20) and only 16 non-test lines changed (threshold: >500).

    ---
    <sub>To override, add a severity-override-{critical,high,medium,low} label.</sub>
    <\!-- pr-severity-bot -->

    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 01, 2026 13:24 UTC
    Bot

    Summary of Changes

    Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

    This pull request addresses an issue where wallet passwords containing newline characters were being truncated when provided via the --stdin flag. By switching from line-based reading to reading until EOF, the command now correctly supports complex passwords while maintaining compatibility with common shell usage patterns.

    Highlights

    Improved Stdin Password Handling: Updated the lncli unlock --stdin command to read the entire input until EOF instead of stopping at the first newline character, ensuring passwords with embedded newlines are handled correctly.
    Maintained Backward Compatibility: Implemented logic to strip only the final trailing newline or carriage return, preserving the functionality for standard shell piping.

  • Expanded Test Coverage: Added three new table-driven test cases to verify handling of embedded newlines, missing trailing newlines, and CRLF terminators.
  • 🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

    <details>
    <summary><b>Using Gemini Code Assist</b></summary>
    <br>

    The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

    <b>Invoking Gemini</b>

    You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

    Feature | Command | Description
    --- | --- | ---
    Code Review | /gemini review | Performs a code review for the current pull request in its current state.
    Pull Request Summary | /gemini summary | Provides a summary of the current pull request in its current state.
    Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
    Help | /gemini help | Displays a list of available commands.

    <b>Customization</b>

    To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

    <b>Limitations & Feedback</b>

    Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.
    </details>

    [^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 01, 2026 13:26 UTC
    Reviewer

    Code Review

    This pull request modifies the lncli unlock --stdin command to read the password until EOF, allowing for passwords with embedded newlines. It also updates the trimming logic to only remove a single trailing newline or carriage return. New test cases were added to verify these changes across different input formats, and the release notes were updated. I have no feedback to provide.

    TechLateef TechLateef commented on code on May 10, 2026 09:49 UTC
    Code Review
    cmd/commands/cmd_walletunlocker.go:1
    @@ -543,11 +543,13 @@ func unlockWithDeps(ctx *cli.Context,
     	// password manager. If the user types the password instead, it will be
     	// echoed in the console.
     	case ctx.IsSet("stdin"):
    -		reader := bufio.NewReader(stdin)
    -		pw, err = reader.ReadBytes('\n')
    -
    -		// Remove carriage return and newline characters.
    -		pw = bytes.Trim(pw, "\r\n")
    +		// Read until EOF so passwords containing newline bytes are
    +		// preserved. A single trailing newline (with optional CR) is
    +		// stripped so the common `echo "pw" | lncli unlock --stdin`
    +		// usage keeps working.
    +		pw, err = io.ReadAll(stdin)

    The switch to io.ReadAll is a great fix for the truncation issue. However, we should handle the err returned here before proceeding to the trim logic, just in case the stdin stream fails or is interrupted.

    		pw, err = io.ReadAll(stdin)
    		if err != nil {
        return err
    }
    

    TechLateef TechLateef commented on May 10, 2026 10:10 UTC
    Contributor

    Overall, this is a solid fix and the test coverage is excellent. I've left one small suggestion regarding error handling for the io.ReadAll call. Once that's addressed, I think this is ready to go!

    0xfandom 0xfandom commented on code on May 18, 2026 09:46 UTC
    Code Review
    cmd/commands/cmd_walletunlocker.go:1
    @@ -543,11 +543,13 @@ func unlockWithDeps(ctx *cli.Context,
     	// password manager. If the user types the password instead, it will be
     	// echoed in the console.
     	case ctx.IsSet("stdin"):
    -		reader := bufio.NewReader(stdin)
    -		pw, err = reader.ReadBytes('\n')
    -
    -		// Remove carriage return and newline characters.
    -		pw = bytes.Trim(pw, "\r\n")
    +		// Read until EOF so passwords containing newline bytes are
    +		// preserved. A single trailing newline (with optional CR) is
    +		// stripped so the common `echo "pw" | lncli unlock --stdin`
    +		// usage keeps working.
    +		pw, err = io.ReadAll(stdin)

    Good catch, applied in the latest push. io.ReadAll error is now returned before trimming so a partial read can no longer slip into the unlock call.

    0xfandom 0xfandom commented on May 18, 2026 09:46 UTC
    Author

    Rebased on master and addressed @TechLateef's review feedback — io.ReadAll error is now handled before the trim step. Ready for another look.

    TechLateef TechLateef approved these changes on May 20, 2026 22:24 UTC
    Approved Reviewer

    LGTM! The error handling looks great now. It looks like some recent changes in the main branch have introduced a merge conflict, so you'll just need to rebase/resolve that before this can be merged.

    litbot-9000 litbot-9000 commented on Jul 23, 2026 03:40 UTC
    Contributor

    @techlateef: review reminder
    @0xfandom, remember to re-request review from reviewers when ready

    saubyk saubyk commented on Jul 23, 2026 03:44 UTC
    Contributor

    !lightninglabs-deploy mute

    0xfandom 0xfandom commented on Jul 23, 2026 06:37 UTC
    Author

    Rebased on latest master. The only conflict was in the 0.22.0 release notes bug-fix section (new entries landed above mine); kept both and re-appended my line. Code and tests are unchanged from the approved version — go test ./cmd/commands/ still passes locally.

    0xfandom 0xfandom commented on Sep 10, 2026 06:59 UTC
    Author

    Rebased onto latest master again — clean this time, no release notes conflict. Code and tests are unchanged from the version @TechLateef approved; go test ./cmd/commands/ still passes.

    This one has been sitting for a while — anything else needed from my side before it can go in?

    saubyk saubyk commented on Sep 25, 2026 03:46 UTC
    Contributor

    Hi @0xfandom, thanks for taking the time to put this together.

    Per the new contributor section of the contribution guidelines, we don't prioritize review of PRs from authors without a track record in the project. Given the current review load, I'm closing this rather than letting it sit.

    Since #5584 already covers this, we'll handle it from that issue; if a fix is warranted a maintainer will pick it up.

    If you'd like to contribute going forward, reviewing open PRs and helping triage issues is the path we recommend. It's a stronger signal of understanding than a first patch, and it makes it a lot easier for us to prioritize your PRs later.

    Reviewers
    Assignees
    0xfandom 0xfandom
    Labels
    risk: low confidence: 86.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.4% (LOW) · Higher = larger blast radius
    33.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 86.2% · Lower = rushed or shallow review
    86.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.6% · Safe to merge
    4.6%