Skip to content

fix(keys): avoid persisting one-off --hd-path overrides for secure-store identities - #2805

Open
Ranjeet2063 wants to merge 3 commits into
stellar:mainfrom
Ranjeet2063:fix/issue-2777-hd-path-secure-store-persistence
Open

Ranjeet2063 wants to merge 3 commits into
stellar:mainfrom
Ranjeet2063:fix/issue-2777-hd-path-secure-store-persistence

Conversation

@Ranjeet2063

Copy link
Copy Markdown

What

Avoid persisting ad-hoc --hd-path overrides to disk when reading and caching unmigrated SecureStore identities.

Why

Closes #2777

In cmd/soroban-cli/src/config/locator.rs::read_key_with_secure_store_cache, when reading a SecureStore identity whose public key has not yet been cached, any --hd-path passed to the command (e.g. stellar keys address alice --hd-path 3) was combined with the identity's configured path (effective = hd_path.or(*persisted_hd_path)) and unconditionally written back to disk via self.write_key(key_or_name, &migrated).

This caused one-off CLI queries using --hd-path to permanently rewrite the stored identity's default account, affecting all subsequent transactions using that identity.

With this change:

  • If --hd-path is provided and differs from the identity's configured derivation path, the derived public key is used in-memory for the current command but is not written back to disk.
  • Disk caching only occurs when deriving for the identity's default configured path (if hd_path.is_none() || hd_path == *persisted_hd_path).
  • Added unit test does_not_persist_hd_path_override_on_one_off_lookup in locator.rs to verify that temporary --hd-path overrides do not mutate the identity file on disk.

Known limitations

N/A

…ore identities

When reading an unmigrated SecureStore identity that does not yet have its public key cached, a caller might specify an ad-hoc --hd-path override (e.g. `stellar keys address alice --hd-path 3`). Previously, this override was written back to the identity file on disk, permanently mutating the identity's default account for future invocations.

Only persist the migrated cache to disk if no override was provided or if the override explicitly matches the identity's configured derivation path.

Closes stellar#2777
Copilot AI lite review requested due to automatic review settings October 15, 2026 06:13
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Oct 15, 2026

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

The successful lookup path is not tested, default-path normalization is incomplete, and documentation is outdated.

2 open findings
What changed in this PR

This PR prevents one-off --hd-path overrides from being persisted for SecureStore identities.

Changes:

  • Restricts cache writes to the configured derivation path.
  • Adds regression coverage for temporary overrides.
File Description Review status
cmd/​soroban-cli/​src/​config/​locator.rs Updates SecureStore caching and adds a unit test. Changes required for test coverage, path normalization, and documentation.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/soroban-cli/src/config/locator.rs Outdated
Comment thread cmd/soroban-cli/src/config/locator.rs Outdated
Update doc comments on `read_key_with_secure_store_cache` and `get_secret_key_with_hd_path` to state that only the identity's configured derivation path is cached to disk, leaving one-off overrides in-memory.

Address review comments on PR stellar#2805.
Copilot AI lite review requested due to automatic review settings October 15, 2026 07:38

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

Normalize None and Some(0) before comparing derivation paths to avoid repeated prompts for legacy identities.

1 open finding
2 resolved since last review

🧠 Review effort: Lite

Comment thread cmd/soroban-cli/src/config/locator.rs Outdated
… override

Compare effective and persisted paths using unwrap_or_default() so None and Some(0) are recognized as the same default derivation path, matching the normalization across the rest of the codebase (e.g. secret.rs). Also ensure the original persisted_hd_path representation is preserved on disk.
Copilot AI lite review requested due to automatic review settings October 15, 2026 15:50

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.

🔵 Needs a closer look

Add regression coverage for non-persisted --hd-path overrides.

0 open findings

1 resolved since last review

🧠 Review effort: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog (Not Ready)

Development

Successfully merging this pull request may close these issues.

--hd-path permanently changes the default account a secure-store identity references

2 participants