Repository navigation
SR-05: Validate wallet wipe marker before resuming reset - #1574
HashEngineering wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository: dashpay/dash-wallet/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
⛔ Final review complete — 1 blocking finding(s) (commit 9955f03) · triage: normal |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
normalbygpt-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); agentphase1-reviewer,muse-spark-1.3-contributor— security-auditor (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort high); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort high); agentphase2-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.
| 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) | ||
| } |
There was a problem hiding this comment.
🔴 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)
| 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) | ||
| } |
There was a problem hiding this comment.
🟡 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)
| @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()) |
There was a problem hiding this comment.
🟡 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)
| @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)) | ||
| } |
There was a problem hiding this comment.
🟡 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.
| @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)
|
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. |
Summary
Verification
Fixes SR-05.