バックアップのセキュリティに関する推奨事項
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
OWASP カテゴリ: MASVS-CODE: コード品質
概要
アプリのバックアップは、ユーザーのデータを保持して、後で新しいデバイスに復元したり、データが失われた場合に復元したりすることを目的としています。アプリのバックアップに関する既存のセキュリティ推奨事項は、Android のバージョンやデバイスのメーカーによって微妙に異なります。共通のテーマは、これらの推奨事項がセンシティブ データの漏洩を防ぐことを目的としています。
標準の Android バックアップ システムは、アプリがデータをクラウドにバックアップしたり、自動バックアップ (デフォルトで有効で、実装に作業を必要とせず、拡張も可能)と Key-Value バックアップを介して新しいデバイスにデータを転送したりするための、最も安全で堅牢かつ簡単なソリューションです。このソリューションを使用することをおすすめします。このソリューションでは、生成されたバックアップ データが他のサードパーティ製アプリからアクセスできないディレクトリに保存されるためです。また、保存データの暗号化、転送中のデータの暗号化、機密データをバックアップから除外できる構成も容易になります。
代わりに、標準の Android バックアップ システムに依存しないバックアップ ソリューションをアプリが実装すると、誤って機密データが漏洩する可能性が高まります。ユーザーデータを漏洩させる標準以外のバックアップ ソリューションの例としては、他のアプリが読み取り可能なディレクトリにアプリデータのコピーを作成する「エクスポート」または「バックアップ」機能を提供するアプリなどがあります。このようなアプリは、(直接的または他の脆弱性を通じて)漏洩しやすくなっています。
影響
アプリのバックアップを設定する際にセキュリティの推奨事項に従うことで、バックアップに含まれる機密データの漏洩を防ぐことができます。実際のデータと攻撃者の意図に応じて、機密データの漏洩により、情報の漏洩、ユーザーのなりすまし、金銭的損失につながる可能性があります。
リスクの軽減
標準の Android バックアップ システムを使用する
標準の Android バックアップ システムでは、転送中と保存中のバックアップ データが常に暗号化されます。この暗号化は、使用している Android のバージョンや、デバイスにロック画面があるかどうかに関係なく適用されます。Android 9 以降では、デバイスにロック画面が設定されている場合、バックアップ データは暗号化されるだけでなく、Google に知られていない鍵で暗号化されます(ロック画面のシークレットで暗号鍵が保護され、エンドツーエンドの暗号化が可能になります)。
一般に、データ ストレージとセキュリティ ガイドラインに沿って操作してください。
バックアップに特に機密性の高いデータが含まれている場合は、このデータを除外するか、除外できない場合は、次のセクションで説明するようにエンドツーエンド暗号化を必須にすることをおすすめします。
バックアップからデータを除外する
バックアップから除外するデータを指定するには、ルールファイルを使用します。このファイルは通常 backup_rules.xml
と呼ばれ、res/xml
アプリ フォルダに配置します。バックアップ ルールの設定方法は、使用する Android のバージョンによって異なります。
- Android バージョン 12(API レベル 31)以降では、
AndroidManifest.xml
内の <application>
要素に android:dataExtractionRules
属性を追加します。
- xml
xml
<application android:name="com.example.foo" android:dataExtractionRules="@xml/backup_rules_extraction">
…
</application>
次に、更新された構成形式に従って、アプリケーションのデータ永続性とセキュリティ要件に従って backup_rules.xml
ファイルを構成します。
backup_rules.xml
ファイルの構成に必要な形式では、デベロッパーはクラウドとデバイス間(D2D)転送の両方にカスタム バックアップ ルールを定義できます。<device-transfer>
属性が設定されていない場合、D2D 移行中にすべてのアプリケーション データが転送されます。ターゲット アプリが Android 12 以降をターゲットとしている場合でも、Android 11(API レベル 30)以前を搭載しているデバイスには、追加のバックアップ ルール セットを含む別のファイルを常に指定する必要があることを強調することが重要です。
- Android バージョン 11 以前の場合は、
AndroidManifest.xml
内の <application>
要素に android:fullBackupContent
属性を追加します。
- xml
xml
<application android:name="com.example.foo" android:fullBackupContent="@xml/backup_rules_full">
…
</application>
次に、ユーザーデータのバックアップに関する記事で報告されている構文を使用して、アプリケーションのデータの永続性とセキュリティの要件に従って backup_rules.xml
ファイルを構成します。
エンドツーエンドの暗号化の必須
機密データをバックアップから除外できない場合は、エンドツーエンドの暗号化を必須にすることをおすすめします。つまり、Android 9 以降で、ロック画面が設定されている場合にのみバックアップを許可します。これは requireFlags="clientSideEncryption"
フラグを使用して実現できます。このフラグは、Android 12 以降は disableIfNoEncryptionCapabilities
に名前を変更し、true
に設定する必要があります。
標準の Android バックアップ システムを使用できない場合
標準の Android バックアップ システムを使用できない場合、バックアップ データを安全に保存し、バックアップから除外するデータを指定することはより複雑になります。これはコードレベルで指定する必要があるため、エラーが発生しやすく、データ漏洩のリスクがあります。このシナリオでは、バックアップの想定動作に変更がないことを確認するため、実装を定期的にテストすることもおすすめします。
リソース
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-26 UTC。"],[],[],null,["# Security recommendations for backups\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nApp backups aim to preserve users' data so that it can later be restored to a\nnew device or in case of data loss. Existing security recommendations regarding\napp backups are nuanced, varying between Android versions and device\nmanufacturers. The common theme is that these recommendations aim at ensuring\nthat no sensitive data is leaked.\n\nThe Standard Android Backup system provides the most secure, robust, and easiest\nsolution for apps to back up their data to the cloud or to transfer data to a\nnew device through [Auto Backup](/identity/data/autobackup)(which is [enabled by default](/identity/data/backup), requires\nno work to implement and can also be extended) and [key-value backup](/guide/topics/data/keyvaluebackup). We\nrecommend using this solution because it stores the resulting backup data in\ndirectories that cannot be accessed by other 3p apps, as well as facilitating\nencryption at rest, encryption in transit, and configurations allowing for the\nexclusion of sensitive data from backups.\n\nIf instead an app implements a backup solution that is not reliant on the\nStandard Android Backup system, this could increase the likelihood of mistakes\nleading to leaks of sensitive data. Examples of non-standard backup solutions\nexposing user data to leaks include apps offering an \"export\" or \"backup\"\ncapability that creates a copy of the app data in directories readable by other\napps, and which is hence prone to being leaked (either directly or through other\nvulnerabilities).\n\nImpact\n------\n\nFollowing security recommendations when setting up app backups prevents the\npotential leak of sensitive data that backups might include. Depending on the\nactual data and on the attacker's intentions, sensitive data leak may lead to\ninformation disclosure, user impersonation, and financial loss.\n\nMitigations\n-----------\n\n### Use the Standard Android Backup system\n\nThe Standard Android Backup system always encrypts backup data in transit and at\nrest. This encryption is applied regardless of the Android version in use and of\nwhether your device has a lock screen. Starting from Android 9, if the device\nhas a lock screen set, then the backup data is not only encrypted, but encrypted\nwith a key not known to Google (the lock screen secret protects the encryption\nkey, thus enabling end-to-end encryption).\n\nIn general remember to follow the [data storage](/training/data-storage) and [security\nguidelines](/privacy-and-security/risks/sensitive-data-external-storage).\n\nIf your backup includes particularly sensitive data, then we recommend to either\nexclude this data or, if you cannot exclude it, require end-to-end encryption as\ndescribed in the following section.\n\n#### Excluding data from backup\n\nYou can specify which data to exclude from a backup using a rules file,\nconventionally called `backup_rules.xml`and placed in the `res/xml` app folder.\nThere are some differences in how backup rules are configured depending on the\nversion of Android that's used:\n\n- [For Android versions 12 (API level 31) and higher](/guide/topics/data/autobackup#include-exclude-android-12), add an `android:dataExtractionRules` attribute to the `\u003capplication\u003e` element within the `AndroidManifest.xml`:\n- xml `xml\n \u003capplication android:name=\"com.example.foo\" android:dataExtractionRules=\"@xml/backup_rules_extraction\"\u003e\n ...\n \u003c/application\u003e`\n\nThen, [configure](/guide/topics/data/autobackup#include-exclude-android-12) the `backup_rules.xml` file according to the\ndata persistence and security requirements of the application, following the\n[updated configuration format](/guide/topics/data/autobackup#xml-syntax-android-12).\n\nThe format required for the `backup_rules.xml` file configuration allows\ndevelopers to define custom backup rules for both Cloud and [Device-To-Device\n(D2D) transfers](/about/versions/12/behavior-changes-12#xml-changes). If the `\u003cdevice-transfer\u003e`attribute is not set, all the\napplication data will be transferred during a D2D migration. It is important to\nhighlight that even if the target application targets Android 12 or higher, a\nseparate file with [an additional set of backup rules](/identity/data/autobackup#include-exclude-android-11) should always be\nspecified for devices running Android 11 (API level 30) or lower.\n\n- [For Android versions 11 and lower](/guide/topics/data/autobackup#include-exclude-android-11), add an `android:fullBackupContent` attribute to the `\u003capplication\u003e` element within the `AndroidManifest.xml`:\n- xml `xml\n \u003capplication android:name=\"com.example.foo\" android:fullBackupContent=\"@xml/backup_rules_full\"\u003e\n ...\n \u003c/application\u003e`\n\nThen, configure the `backup_rules.xml` file according to the data persistence\nand security requirements of the application using the syntax reported in the\n[back up user data](/guide/topics/data/autobackup#include-exclude-android-11) article.\n\n#### Requiring end-to-end encryption\n\nIf you can't exclude sensitive data from your backup, then we recommend\nrequiring end-to-end encryption which means allowing backups only on Android 9\nor higher and only when the lock screen is set. You can achieve this by using\nthe `requireFlags=\"clientSideEncryption\"`flag, which needs to be renamed to\n`disableIfNoEncryptionCapabilities` and set to `true` starting from [Android\n12](/identity/data/autobackup#include-exclude-android-12).\n\n### If you can't use the Standard Android Backup system\n\nIf you can't use the Standard Android Backup system, then securely storing your\nbackup data as well as specifying which data to exclude from your backup is more\ncomplex. This needs to be specified at code level and is consequently\nerror-prone, risking data leaks. In this scenario, it is also recommended to\nregularly test your implementation to ensure that there has been no alteration\nto the expected backup behavior.\n\nResources\n---------\n\n- [Description of the allowBackup attribute](/guide/topics/manifest/application-element#allowbackup)\n- [File-Based Encryption](https://source.android.com/docs/security/features/encryption/file-based)\n- [D2D transfer behavior changes](/about/versions/12/behavior-changes-12#functionality-changes)\n- [Back up user data with Auto Backup](/identity/data/autobackup)\n- [Back up key-value pairs with Android Backup Service](/identity/data/keyvaluebackup)\n- [Control backup on Android 12 or higher](/guide/topics/data/autobackup#include-exclude-android-12)\n- [Control backup on Android 11 and lower](/guide/topics/data/autobackup#include-exclude-android-11)\n- [Understanding PII in Google's contracts and policies](https://support.google.com/analytics/answer/7686480)\n- [Test backup and restore](/identity/data/testingbackup)\n- [Cryptography](/guide/topics/security/cryptography)\n- [Android Keystore system](/training/articles/keystore)\n- [ADB](/tools/adb)\n- [Developer options](/studio/debug/dev-options)"]]