2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
アプリのセキュリティに関するおすすめの方法
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このセクションでは、Android デバイス上のアプリのセキュリティを確保するためのおすすめの方法について説明します。
ソースコード レビュー
ソースコード レビューでは、このドキュメントに掲載されているような広範なセキュリティ問題を検出できます。手動と自動の両方でのソースコードのレビューを強くおすすめします。
- 対象範囲をカバーするため、包括的なセキュリティ ガイダンスに沿ってレビューを実施します。社内外の関連する基準を活用して、一貫性のある完全なレビューとなるようにします。
- Android SDK を使用してすべてのアプリコードに Android Studio Linter などの linter を実行し、識別した問題を修正します。
- バッファ オーバーフローや off-by-one エラーなど、メモリ管理の問題を検出できる自動ツールを使用してネイティブ コードを分析します。
- Android ビルドシステムは、AddressSanitizer や UndefinedBehaviorSanitizer など多くの LLVM サニタイザをサポートしており、メモリ関連の問題に対するランタイム分析に使用できます。libFuzzer を利用して Android でサポートされているファジングと組み合わせると、追加の調査が必要な不審なエッジケースをサニタイザで検出できます。
- 暗号化、支払い処理、PII 処理などのよりリスクの高いコードは、知識のあるセキュリティ評価者がレビューする必要があります。
自動テスト
自動テストは、広範なセキュリティ問題を検出するのに役立ち、定期的に実施する必要があります。
- 最新バージョンの CTS を開発プロセス全体を通じて定期的に実行することで、問題を早期発見し修正までの時間を短縮します。Android では 1 日に何度も行われる自動ビルドプロセスで CTS を継続的インテグレーションの一環として使用しています。
- インターフェースのセキュリティ テストを自動化します。ファズテストなどの不正入力のテストも可能です。Android のビルドシステムは、ファズテストの記述用に libFuzzer をサポートしています。
脆弱性スキャン
脆弱性スキャンは、プリインストールされたアプリに既知のセキュリティ上の脆弱性がないか確認します。高度な検出により、これらの脆弱性に対処するために必要な時間とコストを削減し、ユーザーやデバイスのリスクを回避します。
- 業界に広く認められているアプリの脆弱性スキャンツールを使用してインストール済みのアプリをスキャンし、検出された脆弱性に対応します。
有害な可能性があるアプリ
デバイスにプリインストールされているアプリが、有害な可能性があるアプリ(PHA)ではないことを必ず確認してください。デバイスに含まれるすべてのアプリの動作はデバイス メーカーの責任となります。デバイスを起動する前に、プリロードされているすべてのアプリに脆弱性が存在していないかスキャンしてください。
PHA の詳細や、PHA に対して Google が Play ストア内で実施している対処方法については、Google Play プロテクト デベロッパー ドキュメントをご覧ください。
アプリのインストールと権限
プリインストール アプリに対して過剰な権限が付与されると、セキュリティ上のリスクが発生します。プリインストール アプリには必要最小限の権限を付与して、不要な権限や特権を利用できないようにする必要があります。アプリの権限は AndroidManifest.xml に記述されます。
- プリインストールされたアプリに不要な権限や特権を付与しないでください。システム特権を持つアプリは、高度な機密情報に関わる権限を有する場合があるため、慎重にレビューする必要があります。
- リクエストされている権限がすべて、その特定アプリの機能に関連しており、かつ必要なものであることを確認してください。
- プリインストール アプリが
INSTALL_PACKAGES
権限を使用する場合は、必ずその旨をユーザーに開示するようにしてください。
- UID 0 としてアプリをインストールしないように、デベロッパーに契約で義務付けてください。
- デベロッパーのネットワーク経由でインストールされるすべてのアプリについて、マニフェスト内で宣言されている権限を評価してください。
- デバイスにアプリを配信する前に自動更新ツールやインストーラ アプリのダウンロード URL をすべて Google Safe Browsing API でスキャンするように、デベロッパーに契約で義務付けてください。
アプリ署名
アプリ署名はデバイスのセキュリティで重要な役割を果たし、権限の確認やソフトウェアの更新に使用されます。アプリ署名に使用する鍵を選択する際は、アプリが 1 つのデバイスでのみ利用されるのか、複数のデバイスにまたがって使用されるのかを考慮することが重要です。
- アプリが、AOSP デベロッパー鍵など、一般に知られている鍵で署名されていないことを確認します。
- アプリの署名に使用される鍵が、制限付きで監査可能なアクセスを提供するハードウェア セキュリティ モジュール(HSM)など、業界基準の機密鍵の取り扱い方法に沿って管理されていることを確認します。
- アプリがプラットフォーム キーで署名されていないことを確認します。署名した場合、非常に強力でオペレーティング システムのコンポーネントのみが使用することを想定したプラットフォームの署名権限にアプリがアクセスできるようになります。システムアプリは特権的な権限を使用する必要があります。
- 同じパッケージ名のアプリが異なる鍵で署名されていないことを確認します。これは、プラットフォーム キーを使用する場合など、さまざまなデバイス用にアプリを作成する場合によく発生します。アプリがデバイスに依存しない場合は、デバイス間で同じ鍵を使用します。アプリがデバイス固有の場合は、デバイスと鍵ごとに固有のパッケージ名を作成します。
アプリとプロセスを分離
Android サンドボックス モデルは正しく使用するとアプリやプロセスのセキュリティを強化できます。
ルートプロセスを分離
ルートプロセスは、権限昇格攻撃で最も狙われるターゲットです。ルートプロセスの数を減らすと、権限昇格のリスクが減少します。
- デバイスがルートとして必要最小限のコードを実行していることを確認します。できるだけルートプロセスではなく通常の Android プロセスを使用します。プロセスをデバイスでルートとして実行する必要がある場合は、公開でレビューができるようにプロセスを AOSP 機能リクエストで文書化します。
- 可能であれば、ルートコードは信頼できないデータから分離し、プロセス間通信(IPC)を介してアクセスするようにします。たとえば、ルート機能を Binder 経由でアクセスできる小規模なサービスに縮小し、署名権限付きのサービスをネットワーク トラフィックを処理する特権が小さいかまったくないアプリに公開します。
- ルートプロセスはネットワーク ソケットでリッスンしないでください。
- ルートプロセスには、Java VM などの汎用ランタイムを含めないでください。
システムアプリを分離
一般的に、プリインストールされたアプリを共有システムの固有識別子(UID)で実行してはいけません。アプリがシステムや他の特権サービス(電話など)の共有 UID を使用する必要がある場合、ユーザーがインストールしたサードパーティ製アプリからアクセスできるサービス、ブロードキャスト レシーバ、コンテンツ プロバイダはエクスポートしないでください。
- デバイスがシステムとして最低限必要なコードを実行していることを確認します。可能であれば、システム UID を再使用するのではなく、独自の UID を保有する Android プロセスを使用します。
- 可能であれば、システムコードは信頼できないデータから分離し、IPC は他の信頼できるプロセスにのみ公開します。
- システム プロセスは、ネットワーク ソケットでリッスンしないでください。これは CTS の要件です。
プロセスを分離
Android アプリ サンドボックスでは、アプリがルートプロセスやデバッガを含むシステム上の他のプロセスと分離していることを想定しています。デバッグがアプリとユーザーによって特に有効にされていない限り、アプリはその想定に反しないようにする必要があります。
- ドキュメント化された Android のデバッグ方法を使用しない場合は、ルートプロセスが個々のアプリデータ フォルダ内にあるデータにアクセスしないようにします。
- ドキュメント化された Android のデバッグ方法を使用しない場合は、ルートプロセスがアプリのメモリにアクセスしないようにします。
- 他のアプリやプロセスのデータやメモリにアクセスするアプリがデバイスに含まれていないことを確認します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-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-03-26 UTC。"],[],[],null,["# App security best practices\n\nThis section contains recommendations to ensure the security of apps on\nAndroid devices.\n\nSource code review\n------------------\n\nSource code review can detect a broad range of security issues, including\nthose identified in this document. Android strongly encourages both manual\nand automated source code review.\n\n- Follow comprehensive security guidance when conducting reviews to ensure coverage. Utilize relevant internal or external standards to ensure consistent and complete reviews.\n- Run a linter, such as the [Android Studio linter](https://developer.android.com/studio/write/lint), on all app code using the Android SDK and correct any identified issues.\n- Analyze native code using an automated tool that can detect memory management issues, such as buffer overflows and off-by-one errors.\n- The Android build system supports many of the LLVM sanitizers, such as [AddressSanitizer](/docs/security/test/asan) and [UndefinedBehaviorSanitizer](/docs/security/test/sanitizers#undefinedbehaviorsanitizer), which can be used for runtime analysis of memory-related issues. Combined with fuzzing, supported in Android through [libFuzzer](/docs/security/test/libfuzzer), sanitizers can uncover unusual edge cases requiring further investigation.\n- A knowledgeable security assessor should review higher risk code, such as crypto, payment processing, and PII processing.\n\nAutomated testing\n-----------------\n\nAutomated testing can help detect a broad range of security issues and\nshould be performed regularly.\n\n- Run the latest version of [CTS](/docs/compatibility/cts) regularly throughout the development process to detect problems early and reduce time to correction. Android uses CTS as part of continuous integration in our automated build process, which builds multiple times per day.\n- Automate security testing of interfaces, including testing with malformed inputs (fuzz testing). Android's build system supports [libFuzzer](/docs/security/test/libfuzzer) for writing fuzz tests.\n\nVulnerability scanning\n----------------------\n\nVulnerability scanning can help ensure that pre-installed apps are free of\nknown security vulnerabilities. Advanced detection can reduce the time and\ncost required with addressing these vulnerabilities and preventing risk to\nusers and devices.\n\n- Scan all pre-installed apps using an industry-recognized app vulnerability scanning tool and address detected vulnerabilities.\n\nPotentially Harmful Applications\n--------------------------------\n\nIt is important to ensure that the pre-installed apps on your device aren't\n[Potentially\nHarmful Applications](https://developers.google.com/android/play-protect/phacategories) (PHAs). You are responsible for the behavior of all\napps that are included on your devices. Prior to device launch, scan all\npre-loaded apps for vulnerabilities.\n\nFor more information about PHAs and how Google is combating them in the\nPlay store see the [Google Play Protect\ndeveloper documentation](https://developers.google.com/android/play-protect/).\n\nApp installation and permissions\n--------------------------------\n\nExcessive permissions for pre-installed apps can create a security risk.\nRestrict pre-installed apps to the minimum necessary permissions and ensure they\ndon't have access to unnecessary permissions or privileges. App permissions are\ndescribed in the [AndroidManifest.xml](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/core/res/AndroidManifest.xml).\n\n- Don't grant unnecessary permissions or privileges to pre-installed apps. Thoroughly review apps with system privileges as they can have very sensitive permissions.\n- Ensure that all permissions requested are relevant and necessary for the functionality of that specific app.\n- Ensure there is user disclosure for all pre-installed apps that use the `INSTALL_PACKAGES` permission.\n- Ensure that the developer is contractually obligated not to install any apps as UID 0.\n- Evaluate permissions declared in the manifest of all apps to be installed through the developer's network.\n- Ensure that the developer is contractually obligated to scan all download URLs of auto-updater and installer apps with [Google Safe Browsing API](https://developers.google.com/safe-browsing/) before serving apps to the device.\n\nApp signing\n-----------\n\nApp signatures play an important role in device security and are used for\npermissions checks and software updates. When selecting a key to use for\nsigning apps, it is important to consider whether an app is available\nonly on a single device or common across multiple devices.\n\n- Ensure that apps aren't signed with a key that is publicly known, such as the AOSP developer key.\n- Ensure that keys used to sign apps are managed in a manner consistent with industry-standard practices for handling sensitive keys, including an hardware security module (HSM) that provides limited, auditable access.\n- Ensure that apps aren't signed with the platform key. Doing so gives an app access to platform signature permissions, which are very powerful and only intended to be used by components of the operating system. System apps should use privileged permissions.\n- Ensure that apps with the same package name aren't signed with different keys. This often occurs when creating an app for different devices, especially when using the platform key. If the app is device-independent, use the same key across devices. If the app is device-specific, create unique package names per device and key.\n\nIsolate apps and processes\n--------------------------\n\nThe Android [sandboxing model](/docs/security/app-sandbox)\nprovides extra security around apps and processes when used correctly.\n\n### Isolate root processes\n\nRoot processes are the most frequent target of privilege escalation attacks;\nreducing the number of root processes reduces risk of privilege escalation.\n\n- Ensure that devices run the minimum necessary code as root. Where possible, use a regular Android process rather than a root process. If a process must run as root on a device, document the process in an AOSP feature request so it can be publicly reviewed.\n- Where possible, root code should be isolated from untrusted data and accessed through interprocess communication (IPC). For example, reduce root functionality to a small service accessible through Binder and expose the service with signature permission to an app with low or no privileges to handle network traffic.\n- Root processes must not listen on a network socket.\n- Root processes must not include a general-purpose runtime, such as a Java VM.\n\n### Isolate system apps\n\nIn general, pre-installed apps shouldn't run with the shared system unique\nidentifier (UID). If it is necessary for an app to use the shared UID of\nsystem or another privileged service (e.g., phone), the app shouldn't export\nany services, broadcast receivers, or content providers that can be accessed\nby third-party apps installed by users.\n\n- Ensure devices run the minimum necessary code as system. Where possible, use an Android process with its own UID rather than reusing the system UID.\n- Where possible, system code should be isolated from untrusted data and expose IPC only to other trusted processes.\n- System processes must not listen on a network socket. This is a CTS requirement.\n\n### Isolate processes\n\nThe Android Application Sandbox provides apps with an expectation of\nisolation from other processes on the system, including root processes and\ndebuggers. Unless debugging is specifically enabled by the app and the user,\nno app should violate that expectation.\n\n- Ensure root processes don't access data within individual app data folders, unless using a documented Android debugging method.\n- Ensure root processes don't access memory of apps, unless using a documented Android debugging method.\n- Ensure devices don't include any app that accesses data or memory of other apps or processes."]]