Skip to content

fix: bound LNURL authentication before VSS requests - #36

Open
ben-kaufman wants to merge 1 commit into
masterfrom
fix/bounded-lnurl-auth-20261105
Open

ben-kaufman wants to merge 1 commit into
masterfrom
fix/bounded-lnurl-auth-20261105

Conversation

@ben-kaufman

@ben-kaufman ben-kaufman commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

LNURL authentication could wait indefinitely before the VSS request timeout started. A stalled challenge, signed callback or response body could therefore keep an admitted backup operation alive while the wallet caller waited for it to drain.

This change bounds each header acquisition to ten seconds by directly awaiting the existing provider inside a Tokio timeout. Both the app and dedicated LDK client factories retain their original signer, JWT cache and store binding. Expiry drops that attempt before VSS dispatch; conditional writes remain Rejected for this pre-dispatch failure and retain OutcomeUnknown for a dispatched request whose result is uncertain. Ordinary retries remain unchanged, so this is not a ten-second deadline for an entire operation or wallet wipe.

Validation on the final source:

  • All 28 Rust tests passed, with no failures, ignored tests or retries. One four-row loopback regression holds the real provider at challenge/callback headers or partial bodies, advances virtual time only after the socket boundary is reached, checks zero writes on timeout and late response, then verifies same-client recovery and JWT cache reuse.
  • Format, debug/release builds, documentation and complete all-target Clippy inspection passed. Two existing module-inception warnings are byte-identical to the actual master base.
  • Private iOS and four-ABI Android bindings built successfully, with Swift consumer links and Kotlin consumer compilation/lint. Native archives, symbols, debug pairs, alignment, ZIP/JAR CRCs and generated-interface identity were inspected. Android lint reported zero errors and four dependency-version advisories present in the actual base. Default-disabled lint checks and compile-only consumer checks are not runtime tests.
  • Two independent source reviews covered cancellation, dispatch classification, signer/store ownership and the regression boundary. The entire current-master commit range verified locally before push and on GitHub afterward (verified=true, reason=valid).

This is a source fix for the native dependency finding on synonymdev/bitkit-ios#1121. The committed runtime regression exercises the app conditional-write path. A separate macOS loopback test exercised the dedicated LDK lookup used in the #1121 reset reproduction. With the challenge held on every attempt, the default-namespace read returned AuthError after 110.2 seconds (ten attempts). None reached the VSS endpoint. Once the challenge was released, an explicit read with the same client authenticated and returned an empty list. This measures one native read; Bitkit still pins the previous version. There is no installed-app timeout acceptance, hard real-time guarantee under runtime starvation or running-LDK shutdown claim. Version, released artifacts, app pins, public FFI and server behavior are unchanged. A separately authorized SDK release and app adoption are needed to deliver the fix. Hosted validation is complete on this head: all four workflows and six jobs passed on attempt 1 (Rust, manifest validation, iOS, Android). The synthetic checkout has the exact published tree and all 45 frozen inputs. All 28 Rust tests passed; both uploaded native artifacts were downloaded once and fully checked for hashes, CRCs, base API exports, platform/ABI metadata, Android debug pairing and 16 KiB segment alignment. Complete logs and annotations retain two base Clippy warnings, three base Python updater warnings and tooling advisories. Five OS-specific action skips and two Gradle NO-SOURCE tasks are not runtime passes. Hosted checks did not run Android lint, consumer fixtures or installed apps; those local results and the outstanding app acceptance remain separate.

@talosmachina talosmachina 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.

No findings. Wraps the LNURL-auth JWT provider in a 10 s tokio::time::timeout for both the app client and the dedicated LDK client, so a stalled challenge, callback or body fails before any VSS request is sent. Reviewed 1a5b788, full tier (auth path).

Build skipped: talos-pr-run could not read the author's repo permission with this token and fails closed, so this review is static. CI Tests and Clippy are green on this head; iOS and Android bindgen were still pending when I read it.

What I checked, and 5 candidates I ruled out

Read in full: src/auth.rs, src/auth/tests.rs, src/conditional.rs, src/implementation.rs (client construction), src/ldk_client.rs, src/lib.rs, plus vss-client-ng 0.4.0 headers/lnurl_auth_jwt.rs, client.rs and util/retry.rs (the version Cargo.lock pins).

Ruled out

  • Cancellation leaves a bad JWT cache: get_jwt_token writes the cache only after fetch_jwt_token returns, and no lock is held across an await, so dropping the future mid-leg leaves the previous cache state and the next call re-authenticates.
  • Timeout misclassified on the conditional path: post_request maps any header error to AuthError before dispatch, and classify turns AuthError into Rejected, which is correct since nothing reached VSS. OutcomeUnknown is untouched for dispatched requests.
  • Timer not available at runtime: the FFI runtime is built with enable_all(), and tokio now carries the time feature in normal dependencies, not only dev.
  • Regular client can still wait long: on inner the timeout surfaces as AuthError, which the retry policy does not skip, and max_total_delay counts backoff only, so ten attempts can each spend up to 10 s. The PR body states this is per acquisition, not per operation, so it is deliberate.
  • Behaviour change in ldk_client.rs beyond the wrapper: the other hunks are rustfmt reflow only; retry policy and key derivation are byte-for-byte the same.

Merge confidence: 4/5, the LDK client's wrapped provider has no test exercising it (the regression covers the app conditional path) and bindgen CI was still pending.

@piotr-iohk piotr-iohk 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.

QA review

Scope: Full review of the complete PR diff against its merge base, at 1a5b788. No saved baseline was available, so no coverage is inherited.

No new actionable code findings.

The 10-second bound applies to each header acquisition and is wired into both LnurlAuthToJwtProvider construction sites, the app client and the dedicated LDK client. A timeout drops the attempt before post_request sends anything to VSS. The JWT cache is written only after a completed fetch and no lock is held across an await, so an expired attempt leaves no partial state. Conditional writes return Rejected for this pre-dispatch failure, and OutcomeUnknown handling for dispatched requests is unchanged. The other ldk_client.rs hunks are formatting only.

Worst-case wait on retrying clients: this is not a 10-second operation limit, as the PR states. The timeout surfaces as AuthError, which the retry policy does not skip, and max_total_delay counts backoff only. From source, a fully stalled auth server would hold a retrying call for about 110 seconds: 10 attempts of 10 seconds plus about 10.1 seconds of backoff. That is the path in the originating bitkit-ios finding, so the reset wait there would become bounded at about that length, not 10 seconds.

Validation: the hosted Tests job ran on the merge of this head into the reviewed base and reported 28 passed, including auth_timeout_rejects_before_dispatch_and_same_provider_can_retry. Clippy also passed on this head. That regression exercises only the app conditional path, so the LDK factory wiring and the retrying clients are source-checked only.

Limitations: no Rust toolchain was available and static.crates.io was unreachable, so nothing was built or run locally. The dependency was read from the vss-client v0.4.0 tag, not the crate archive, so the Cargo.lock checksum was not verified against it. The PR body mixes requirements with fix notes, so discovery was not fully blind to them. bitkit-ios was checked only for how it calls this SDK; it was not reviewed.

Dependency: the fix reaches the app only after an SDK release and pin update. bitkit-ios#1121 still pins eba41ef.

Suggested additional test cases

  • Rust, dedicated LDK client on the retry path. Setup: reuse the loopback server from src/auth/tests.rs, hold every /challenge response, and use paused Tokio time. Action: build LdkVssClient::new_with_lnurl_auth and call get. Expected: VssError::AuthError after 10 challenge attempts, at about 110 seconds of virtual time, with zero VSS requests. Removing the wrapper at the LDK factory should fail this test; the current suite would not catch that.
  • iOS, after the SDK is adopted. Setup: a state that needs a fresh JWT, with an LNURL-auth server that accepts the connection but holds its response. Action: read a key on the VSS Debug LDK tab, leave the screen, then choose Security → Reset. Expected: the read fails and the reset reaches credential deletion within about 110 seconds, with no VSS request sent.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@ovi-reviewer ovi-reviewer 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.

Verdict: ✅ Approve

Findings: None.

QA for 1a5b788:

Native authentication and backup regressions ✅ The exact-head Rust library suite passed, including all four authentication stall boundaries.

cargo test --locked --lib: 28 passed. The authentication regression holds challenge or callback responses before headers or during a partial body, verifies Rejected with no VSS writes after expiry and late response, then checks same-client recovery and JWT reuse.

Rendered command output:

Dedicated LDK authentication retries settle without VSS dispatch ✅ A loopback regression observed ten timed-out attempts, zero VSS requests, and same-client recovery.

A supplemental test exercised LdkVssClient::new_with_lnurl_auth and get with unchanged production source. Each real challenge request reached the socket before advancing Tokio time. The call returned AuthError after 110.228 seconds of virtual time; no VSS request was sent. The same client then authenticated once and completed two writes using its cached JWT.

Removing only the LDK factory wrapper made this probe fail waiting for the second challenge. Temporary test and control edits were restored. This directly exercises the native retry case suggested in the prior QA review; it does not establish wall-clock wipe timing.

Rendered command output:

Check: release library builds with production timer features ✅ The locked release build succeeded on the restored reviewed tree.

cargo build --locked --release --lib passed without test features.

Rendered command output:

Platform binding generation was not repeated; the current-head hosted iOS bindgen and Android bindgen workflows passed. These are build checks, not installed-app tests.

No device run: this repository provides a native library, and the PR explicitly leaves installed-app acceptance for SDK release and app adoption. The suggested iOS Debug → Reset journey was not driven; wallet wipe and running-LDK shutdown remain outside this native validation. Ten seconds bounds each header acquisition, not the complete retrying operation.

Full review of eba41ef..1a5b788: all changed files, both client factories, and reachable authentication, cache, dispatch, error-classification, runtime and retry paths, including resolved vss-client-ng 0.4.0 source. No actionable defects found in either independent source pass.


Reviewed by gpt-6.1-sol-high

@ovitrif ovitrif left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

utAck

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.

4 participants