Skip to content

[Bug] decryptKeystore has dead code, potential infinite recursion and wrong error classification #302

Description

@zakaziko86

Bug Description

decryptKeystore in src/lib/actions/BaseAction.ts (lines 65-79)
has three issues combined.

Issue 1: Dead Code (Unreachable line 78)

When attempt >= MAX_PASSWORD_ATTEMPTS, failSpinner calls
process.exit(1). The recursive call after it is unreachable.

Issue 2: Potential Infinite Recursion

If failSpinner is ever called with shouldExit=false,
the recursion continues indefinitely — no return or throw exists
after failSpinner.

Issue 3: Wrong Error Classification

The catch block catches ALL errors from fromEncryptedJson
(malformed JSON, crypto errors, corrupted keystore) and treats
them all as wrong password. Users with corrupted keystores
get prompted 3 times with "Invalid password" before a
misleading "Maximum attempts exceeded" error.

Suggested Fix

} catch (error: any) {
  const isPasswordError = error.message?.includes('password') || 
                          error.message?.includes('decrypt');
  if (!isPasswordError) throw error; // re-throw non-password errors
  if (attempt >= BaseAction.MAX_PASSWORD_ATTEMPTS) {
    this.failSpinner(`Maximum password attempts exceeded.`);
    return; // explicit return after failSpinner
  }
  return await this.decryptKeystore(keystoreJson, attempt + 1);
}

File

src/lib/actions/BaseAction.ts lines 65-79
Severity: High
Already reported: No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions