Skip to content

SR-05: Validate wallet wipe marker before resuming reset - #1574

Closed
HashEngineering wants to merge 1 commit into
dashpay:fix/sync-process-stallsfrom
HashEngineeringSolutions:fix/sr-05-wallet-wipe-marker
Closed

HashEngineering wants to merge 1 commit into
dashpay:fix/sync-process-stallsfrom
HashEngineeringSolutions:fix/sr-05-wallet-wipe-marker

Conversation

@HashEngineering

Copy link
Copy Markdown
Collaborator

Summary

  • bind wallet-wipe.pending to a versioned marker plus install-local no-backup token
  • ignore and best-effort remove empty, malformed, or restored markers instead of resuming a destructive wipe
  • update launch and wipe teardown checks to validate the marker before deleting wallet data
  • add regression coverage for empty planted markers and files/ restore without the install token

Verification

  • ./gradlew :wallet:testDevnetDebugUnitTest --tests de.schildbach.wallet.util.WalletWipeSequenceTest

Fixes SR-05.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

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

🗂️ Base branches to auto review (2)
  • feat/kotlin-sdk-phase-.*
  • feat/kotlin-sdk-phase\d+

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: Repository: dashpay/dash-wallet/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: ea97e051-4bbb-480f-ade1-c68ddfc104b7

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

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.

@thepastaclaw

thepastaclaw commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

⛔ Final review complete — 1 blocking finding(s) (commit 9955f03) · triage: normal

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

Final validation — Phase 1 + Phase 2

The token-bound marker closes the planted/restored-marker path, but it drops compatibility with the bare marker written by the immediately preceding implementation. An interrupted wipe from that version can therefore have its recovery marker deleted during upgrade and proceed into normal wallet startup with partially destroyed data. Additional non-blocking issues remain around unbounded marker reads and incomplete regression assertions.

🔴 1 blocking | 🟡 3 suggestion(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — This is a contained but substantive change to wallet-reset state validation and destructive data-deletion control flow, with persistence and lifecycle edge cases requiring meaningful review, but it does not itself alter funds movement, key handling, cryptography, consensus, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `wallet/src/de/schildbach/wallet/util/WalletWipeState.kt`:
- [BLOCKING] wallet/src/de/schildbach/wallet/util/WalletWipeState.kt:89-94: Do not discard legacy pending markers during upgrade
  The previous implementation created an empty `wallet-wipe.pending` file, while this implementation requires a `v1` body tied to an install token in `noBackupFilesDir`. If an older build is killed during a reset, its bare marker and partially destroyed wallet data survive an app upgrade, but the new build has no token for that marker. `isPending()` therefore treats the marker as invalid, deletes it, and returns false; `WalletApplication` then continues normal startup and can load or expose the half-wiped wallet state. The migration path must preserve the recovery guard for legacy markers: it must not resume a destructive wipe without authentication, but it also must not remove the marker and permit normal wallet loading of an unknown partially destroyed state.
- [SUGGESTION] wallet/src/de/schildbach/wallet/util/WalletWipeState.kt:85-94: Bound and validate marker files before reading them
  The launch-time validation reads both the marker and install-token files with `readText()` before checking their size or regular-file type. A restored or planted oversized marker/token can therefore cause unbounded main-thread I/O and allocation during `Application.onCreate`. A directory named `wallet-wipe.pending` also passes `exists()`, causes `readText()` to throw, and bypasses `removeInvalidMarker()`, leaving the same invalid entry to trigger on every launch. Check `isFile` and a small maximum length for both files before reading, and route invalid entries through the existing best-effort cleanup.

In `wallet/test/de/schildbach/wallet/util/WalletWipeSequenceTest.kt`:
- [SUGGESTION] wallet/test/de/schildbach/wallet/util/WalletWipeSequenceTest.kt:75-82: Exercise invalid marker contents with an existing install token
  Both rejection tests use a no-backup directory without a token. Because `token != null && file.readText(...) == markerBody(token)` short-circuits when the token is absent, those tests do not exercise marker-body validation. Add cases that establish a token with `begin()`, then replace the marker with empty, malformed, unsupported-version, and mismatched-token contents, and assert that each is rejected and removed. This protects the version and token comparison that actually authorizes destructive recovery.
- [SUGGESTION] wallet/test/de/schildbach/wallet/util/WalletWipeSequenceTest.kt:85-93: Assert that restored markers are removed
  The restored-marker test verifies only that `isPending()` returns false. The implementation promises best-effort removal of invalid markers, so the test should also assert that `wallet-wipe.pending` no longer exists. This would catch a regression where restored markers are ignored but retained indefinitely, and it complements the missing valid-token malformed-body coverage.

Comment on lines +89 to +94
val token = readInstallToken(noBackupFilesDir)
val valid = token != null && file.readText(Charsets.UTF_8) == markerBody(token)
if (!valid) {
log.warn("ignoring invalid wallet-wipe marker at {}", file)
removeInvalidMarker(file)
}

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.

🔴 Blocking: Do not discard legacy pending markers during upgrade

The previous implementation created an empty wallet-wipe.pending file, while this implementation requires a v1 body tied to an install token in noBackupFilesDir. If an older build is killed during a reset, its bare marker and partially destroyed wallet data survive an app upgrade, but the new build has no token for that marker. isPending() therefore treats the marker as invalid, deletes it, and returns false; WalletApplication then continues normal startup and can load or expose the half-wiped wallet state. The migration path must preserve the recovery guard for legacy markers: it must not resume a destructive wipe without authentication, but it also must not remove the marker and permit normal wallet loading of an unknown partially destroyed state.

source: gpt-6-astra (phase2-reviewer: security-auditor)

Comment on lines +85 to +94
val file = marker(filesDir)
if (!file.exists()) {
return false
}
val token = readInstallToken(noBackupFilesDir)
val valid = token != null && file.readText(Charsets.UTF_8) == markerBody(token)
if (!valid) {
log.warn("ignoring invalid wallet-wipe marker at {}", file)
removeInvalidMarker(file)
}

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.

🟡 Suggestion: Bound and validate marker files before reading them

The launch-time validation reads both the marker and install-token files with readText() before checking their size or regular-file type. A restored or planted oversized marker/token can therefore cause unbounded main-thread I/O and allocation during Application.onCreate. A directory named wallet-wipe.pending also passes exists(), causes readText() to throw, and bypasses removeInvalidMarker(), leaving the same invalid entry to trigger on every launch. Check isFile and a small maximum length for both files before reading, and route invalid entries through the existing best-effort cleanup.

source: muse-spark-1.3-contributor (phase1-reviewer: general, security-auditor)

Comment on lines +75 to +82
@Test
fun `an empty marker planted before launch is ignored and removed`() {
val filesDir = newFilesDir()
val noBackupFilesDir = newNoBackupFilesDir()
File(filesDir, WalletWipeState.MARKER_FILE_NAME).createNewFile()

assertFalse(WalletWipeState.isPending(filesDir, noBackupFilesDir))
assertFalse(File(filesDir, WalletWipeState.MARKER_FILE_NAME).exists())

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.

🟡 Suggestion: Exercise invalid marker contents with an existing install token

Both rejection tests use a no-backup directory without a token. Because token != null && file.readText(...) == markerBody(token) short-circuits when the token is absent, those tests do not exercise marker-body validation. Add cases that establish a token with begin(), then replace the marker with empty, malformed, unsupported-version, and mismatched-token contents, and assert that each is rejected and removed. This protects the version and token comparison that actually authorizes destructive recovery.

source: gpt-6-astra (phase2-reviewer: general)

Comment on lines +85 to 93
@Test
fun `a marker restored without this install token is ignored`() {
val filesDir = newFilesDir()
val originalNoBackupFilesDir = newNoBackupFilesDir()
val restoredNoBackupFilesDir = newNoBackupFilesDir()
assertTrue(WalletWipeState.begin(filesDir, originalNoBackupFilesDir))

assertFalse(WalletWipeState.isPending(filesDir, restoredNoBackupFilesDir))
}

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.

🟡 Suggestion: Assert that restored markers are removed

The restored-marker test verifies only that isPending() returns false. The implementation promises best-effort removal of invalid markers, so the test should also assert that wallet-wipe.pending no longer exists. This would catch a regression where restored markers are ignored but retained indefinitely, and it complements the missing valid-token malformed-body coverage.

Suggested change
@Test
fun `a marker restored without this install token is ignored`() {
val filesDir = newFilesDir()
val originalNoBackupFilesDir = newNoBackupFilesDir()
val restoredNoBackupFilesDir = newNoBackupFilesDir()
assertTrue(WalletWipeState.begin(filesDir, originalNoBackupFilesDir))
assertFalse(WalletWipeState.isPending(filesDir, restoredNoBackupFilesDir))
}
assertFalse(WalletWipeState.isPending(filesDir, restoredNoBackupFilesDir))
assertFalse(File(filesDir, WalletWipeState.MARKER_FILE_NAME).exists())

source: muse-spark-1.3-contributor (phase1-reviewer: general, security-auditor)

@HashEngineering

Copy link
Copy Markdown
Collaborator Author

Superseded by #1577, which includes the review fixes and publishes the SR-05 branch directly in dashpay/dash-wallet. Unverified markers now preserve a recovery guard instead of allowing normal startup or deletion; bounded reads and expanded regression tests are included. CodeRabbit review has been requested on #1577.

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.

2 participants