Skip to content

Keep app data off device-to-device transfer and backups - #320

Open
lazzurs wants to merge 1 commit into
parawanderer:mainfrom
lazzurs:fix/s05-exclude-device-transfer
Open

lazzurs wants to merge 1 commit into
parawanderer:mainfrom
lazzurs:fix/s05-exclude-device-transfer

Conversation

@lazzurs

@lazzurs lazzurs commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes audit finding S-05: app data was not excluded from Android 12+ device-to-device transfer. android:allowBackup="false" turns off cloud backup, but for an app targeting API 31+ it does not turn off the phone-to-phone copy when someone sets up a new phone. data_extraction_rules.xml was still the Android Studio template with no <device-transfer> section, so everything the app stores was eligible to be copied, including the Room database with every tag's private keys and location history.

What changes

  • data_extraction_rules.xml (Android 12+): <device-transfer> and <cloud-backup> both exclude every domain (root, file, database, sharedpref, external and the four device_* ones), each with path=".", and nothing is included.
  • backup_rules.xml (fullBackupContent, Android 11 and older): the same excludes. On those versions allowBackup="false" already covers transfer too, so this only matters if allowBackup is ever turned on.
  • The <cloud-backup> section isn't used while allowBackup is false either. Both are filled in so that flipping allowBackup later doesn't quietly start uploading the database.
  • The reasoning is in a comment at the top of data_extraction_rules.xml, and AGENTS.md rule 1's "there is no backup" now mentions transfer too.
  • No code changes, no manifest change (it already points at both files).

Why everything, not just the database and user_auth

The audit and #318 suggest at least the database and the user_auth DataStore. I excluded everything, for these reasons:

  • Keystore keys never move. The Apple session (user_auth), the iCloud link and the extra sources' passwords are encrypted with Keystore keys. On a new phone they'd arrive as data nothing can decrypt. The app copes with that at each read (MembershipState.KEYS_GONE, "has to be entered again"), but those are error paths, and a new phone shouldn't start on one.
  • The Anisette identity is one machine per install (AGENTS.md rules 11 and 21). files/anisette/ and the anisette-identity preferences moving would put the same machine identity on two phones.
  • A partial copy is a state no install is otherwise in, for example onboarding marked done and settings present with no tags and no session. A fresh install is the state everything is tested from.
  • The cost is small and expected: on a new phone you sign in again and import your export again, as after a reinstall. Export Tags and Export History already move tags and history deliberately, with the bundle locked by a code.
  • Settings are lost on transfer too. They're few and quick to set again, and keeping them would mean this file tracking every preferences file the app writes, which goes stale without anything failing.

The cache, code_cache and no_backup directories are never backed up or transferred, so they don't need rules.

Tests

  • KeepingAppDataOnThisPhoneTest (JVM, reads the source files like TrustingApplesProvisioningHostsTest): the manifest keeps allowBackup="false" and points at both rule files; <device-transfer>, <cloud-backup> and <full-backup-content> each exclude exactly every domain, each as a whole (path="."), with no <include>.
  • Checked it can fail: against main's template data_extraction_rules.xml, 2 of the 4 tests go red (device transfer and cloud backup).

Verified

  • Local: :app:testDebugUnitTest (578 tests, 0 failures, 1 skipped), check_java_imports.py.
  • :app:lintDebug: no findings in either rule file or the manifest's backup attributes (lint validates the domains and paths). Lint's existing errors on main are unchanged and unrelated.

Not verified

  • I haven't run a real device-to-device transfer. Behaviour varies by OEM transfer tool, and testing it needs two Android 12+ phones. Android's own bmgr tooling could simulate a D2D transfer on an emulator, but I haven't done that either.
  • Whether every OEM tool honours <device-transfer> is up to the OEM. Google's documentation says it applies to D2D transfers on Android 12+.

Relationship

Part of #318 (the first item under "Security hardening"). parawanderer agreed to this follow-up on #315. Independent of #313 and #315: branched from main, and the only file it shares with either is AGENTS.md, where it edits rule 1 and #315 adds rule 23. It merges cleanly with both (git merge-tree).

🤖 Generated with Claude Code

allowBackup="false" turns off cloud backup, but on Android 12+ it does
not turn off device-to-device transfer, and data_extraction_rules.xml
was still the Android Studio template. So the database with every
tag's private keys and location history, the Keystore-encrypted
session and the Anisette identity were all eligible to be copied to a
new phone.

Exclude every domain in <device-transfer>, and in <cloud-backup> and
the legacy backup_rules.xml too, so turning allowBackup on later does
not start copying them. A new phone starts as a fresh install. The
reasons for excluding everything rather than just the database are in
the XML comment.

KeepingAppDataOnThisPhoneTest pins the manifest attributes and every
excluded domain on the JVM.

Part of parawanderer#318 (audit S-05).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@parawanderer

parawanderer commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Sounds good, though I saw the emulator tests fail which is worth looking into/fixing. If you don't want to run those on your machine, it's completely doable to e.g. have an LLM fix it with the CI running them for you here (I did that on one of my laptops where I didn't want to install the android dev bloat).

EDIT: I see it's something C++ and you did not realistically change anything here that should impact that. So I will look into it

@parawanderer

Copy link
Copy Markdown
Owner

Looking it with an agent now: that failure is the time-of-day flake you identified in #313 and #314, not anything this changes: DebugModeReachesEveryScreenTest says "no history row was built at all" because AMapWithTagsOnIt seeds each tag's location at now − 2h, which is yesterday when the suite runs between 00:00 and 02:00 UTC. This run hit it at 00:14. The other 858 tests passed and the native build was fine, so the CMake and NDK lines in the log are just setup.

I've rerun the failed job. TheWholeAppJourneyTest already seeds from local midnight instead; I'm changing AMapWithTagsOnIt to do the same, so it stops costing everybody a 22-minute rerun.

Drafted by Claude Code, reviewed by @parawanderer

This branch was previously deployed

1 inactive deployment
Android Build — 1f68be9b Deployed Nov 24, 2026 by lazzurs via Instrumented tests (emulator) #429
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