คําแนะนําด้านความปลอดภัยสําหรับการสํารองข้อมูล
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หมวดหมู่ OWASP: MASVS-CODE: คุณภาพโค้ด
ภาพรวม
การสำรองข้อมูลแอปมีจุดประสงค์เพื่อเก็บข้อมูลของผู้ใช้ไว้เพื่อให้กู้คืนข้อมูลไปยังอุปกรณ์เครื่องใหม่ได้ภายหลัง หรือในกรณีที่ข้อมูลสูญหาย คําแนะนําด้านความปลอดภัยที่มีอยู่เกี่ยวกับการสํารองข้อมูลแอปมีความซับซ้อนแตกต่างกันไปตามเวอร์ชัน Android และผู้ผลิตอุปกรณ์ ประเด็นหลักคือคําแนะนําเหล่านี้มีจุดมุ่งหมายเพื่อไม่ให้ข้อมูลที่ละเอียดอ่อนรั่วไหล
ระบบการสำรองข้อมูล Android มาตรฐานเป็นโซลูชันที่ปลอดภัย มีประสิทธิภาพ และใช้งานง่ายที่สุดสำหรับแอปในการสำรองข้อมูลไปยังระบบคลาวด์หรือโอนข้อมูลไปยังอุปกรณ์เครื่องใหม่ผ่านการสำรองข้อมูลอัตโนมัติ (ซึ่งเปิดใช้โดยค่าเริ่มต้น ใช้งานได้ง่าย และขยายการให้บริการได้) และการสำรองข้อมูลแบบคีย์-ค่า เราขอแนะนำให้ใช้โซลูชันนี้เนื่องจากจะจัดเก็บข้อมูลสำรองที่ได้ไว้ในไดเรกทอรีที่แอปของบุคคลที่สามอื่นๆ เข้าถึงไม่ได้ รวมถึงอำนวยความสะดวกในการเข้ารหัสข้อมูลที่เก็บไว้ การเข้ารหัสระหว่างการรับส่ง และการกำหนดค่าที่อนุญาตให้ยกเว้นข้อมูลที่ละเอียดอ่อนจากการสำรองข้อมูล
แต่หากแอปใช้โซลูชันการสำรองข้อมูลที่ไม่อาศัยระบบการสำรองข้อมูล Android มาตรฐาน ก็อาจเพิ่มโอกาสที่จะเกิดความผิดพลาดซึ่งนำไปสู่การรั่วไหลของข้อมูลที่ละเอียดอ่อน ตัวอย่างโซลูชันการสำรองข้อมูลที่ไม่เป็นไปตามมาตรฐานซึ่งทำให้ข้อมูลผู้ใช้มีความเสี่ยงที่จะรั่วไหล ได้แก่ แอปที่เสนอความสามารถในการ "ส่งออก" หรือ "สำรองข้อมูล" ซึ่งสร้างสำเนาข้อมูลแอปในไดเรกทอรีที่แอปอื่นๆ อ่านได้ และทำให้ข้อมูลมีความเสี่ยงที่จะรั่วไหล (โดยตรงหรือผ่านช่องโหว่อื่นๆ)
ผลกระทบ
การปฏิบัติตามคำแนะนำด้านความปลอดภัยเมื่อตั้งค่าการสำรองข้อมูลแอปจะช่วยป้องกันไม่ให้ข้อมูลที่ละเอียดอ่อนซึ่งอาจรวมอยู่ในข้อมูลสำรองรั่วไหล การเปิดเผยข้อมูลที่ละเอียดอ่อนอาจนำไปสู่การเปิดเผยข้อมูล การแอบอ้างเป็นผู้ใช้ และการสูญเสียทางการเงิน ทั้งนี้ขึ้นอยู่กับข้อมูลจริงและเจตนาของผู้โจมตี
การลดปัญหา
ใช้ระบบการสำรองข้อมูล Android มาตรฐาน
ระบบการสำรองข้อมูล Android มาตรฐานจะเข้ารหัสข้อมูลสำรองทั้งในระหว่างการรับส่งและขณะที่ไม่มีการเคลื่อนไหวเสมอ การเข้ารหัสนี้จะมีผลไม่ว่าคุณจะใช้ Android เวอร์ชันใดก็ตามและไม่ว่าอุปกรณ์จะมีหน้าจอล็อกหรือไม่ก็ตาม ตั้งแต่ Android 9 เป็นต้นไป หากอุปกรณ์ตั้งค่าหน้าจอล็อกไว้ ข้อมูลสำรองก็จะไม่ได้เข้ารหัสเท่านั้น แต่ยังเข้ารหัสด้วยคีย์ที่ Google ไม่รู้จัก (ข้อมูลลับของหน้าจอล็อกจะปกป้องคีย์การเข้ารหัสด้วย ดังนั้นจึงเปิดใช้การเข้ารหัสจากต้นทางถึงปลายทาง)
โดยทั่วไป โปรดอย่าลืมปฏิบัติตามหลักเกณฑ์ด้านพื้นที่เก็บข้อมูลและความปลอดภัย
หากข้อมูลสํารองมีข้อมูลที่ละเอียดอ่อนเป็นพิเศษ เราขอแนะนําให้ยกเว้นข้อมูลนี้ หรือหากยกเว้นไม่ได้ ให้ใช้การเข้ารหัสจากต้นทางถึงปลายทางตามที่อธิบายไว้ในส่วนต่อไปนี้
การยกเว้นข้อมูลจากการสำรองข้อมูล
คุณระบุข้อมูลที่จะยกเว้นจากข้อมูลสำรองได้โดยใช้ไฟล์กฎ ซึ่งโดยทั่วไปจะเรียกว่า backup_rules.xml
และวางไว้ในโฟลเดอร์แอป res/xml
การกำหนดค่ากฎการสำรองข้อมูลจะแตกต่างกันไปบ้างโดยขึ้นอยู่กับเวอร์ชัน Android ที่ใช้
- สำหรับ Android เวอร์ชัน 12 (API ระดับ 31) ขึ้นไป ให้เพิ่มแอตทริบิวต์
android:dataExtractionRules
ลงในองค์ประกอบ <application>
ภายใน AndroidManifest.xml
ดังนี้
- 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 และต่ำกว่า ให้เพิ่มแอตทริบิวต์
android:fullBackupContent
ลงในองค์ประกอบ <application>
ภายใน AndroidManifest.xml
ดังนี้
- xml
xml
<application android:name="com.example.foo" android:fullBackupContent="@xml/backup_rules_full">
…
</application>
จากนั้นกำหนดค่าไฟล์ backup_rules.xml
ตามข้อกำหนดด้านความต่อเนื่องของข้อมูลและความปลอดภัยของแอปพลิเคชัน โดยใช้ไวยากรณ์ที่รายงานในบทความสำรองข้อมูลผู้ใช้
กำหนดให้ใช้การเข้ารหัสจากต้นทางถึงปลายทาง
หากยกเว้นข้อมูลที่ละเอียดอ่อนออกจากข้อมูลสำรองไม่ได้ เราขอแนะนำให้ใช้การเข้ารหัสจากต้นทางถึงปลายทาง ซึ่งหมายความว่าจะอนุญาตการสำรองข้อมูลใน Android 9 ขึ้นไปเท่านั้นและเมื่อตั้งค่าหน้าจอล็อกแล้วเท่านั้น ซึ่งทำได้โดยใช้requireFlags="clientSideEncryption"
Flag ซึ่งต้องเปลี่ยนชื่อเป็น disableIfNoEncryptionCapabilities
และตั้งค่าเป็น true
ตั้งแต่วันที่ Android 12 เป็นต้นไป
หากใช้ระบบการสำรองข้อมูล 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)"]]