ディレクトリの FileProvider への不適切な公開
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
OWASP カテゴリ: MASVS-STORAGE: ストレージ
概要
不適切に構成された FileProvider
は、ファイルやディレクトリを意図せず攻撃者に公開する可能性があります。構成によっては、攻撃者はこれらの公開されたファイルに読み書きを実行できるため、機密情報の流出や、最悪の場合、任意のコードが実行される可能性もあります。たとえば、<root-path>
が構成されているアプリの場合、攻撃者がデータベースに保存されている機密情報にアクセスする、アプリのネイティブ ライブラリを上書きするなど、任意のコードが実行されるおそれがあります。
影響
影響は、構成やファイルの内容によって異なりますが、一般的にはデータ漏洩(読み取り時)やファイルの上書き(書き込み時)が発生します。
リスクの軽減
構成で <root-path> パス要素を使用しない
<root-path>
は、デバイスのルート ディレクトリ(/
)に対応します。構成でこれを許可すると、アプリのサンドボックスや /sdcard
ディレクトリを含むファイルやフォルダに任意でアクセスでき、広範な攻撃対象領域が攻撃者に提供されます。
限られたパス範囲を共有する
パス構成ファイルでは、.
や /
のような幅広いパス範囲を共有しないでください。この操作をすると、機密ファイルが誤って公開されるおそれがあります。限られた狭い範囲のパスのみを共有し、共有するファイルのみがこのパスに含まれるようにします。これにより、機密ファイルが誤って公開されるのを防ぐことができます。
より安全な設定の一般的な構成ファイルは次のようになります。
XML
<paths>
<files-path name="images" path="images/" />
<files-path name="docs" path="docs" />
<cache-path name="cache" path="net-export/" />
</paths>
外部 URI を確認して検証する
(content
スキームを使用して)外部 URI を検証し、それらがアプリのローカル ファイルを指していないことを確認します。これにより、不用意な情報漏洩を防ぐことができます。
最小限のアクセス権を付与する
content URI
には読み取りと書き込みの両方のアクセス権を割り当てることができます。必要最小限のアクセス権のみが付与されていることを確認してください。
たとえば、読み取り権限のみが必要な場合は、明示的に FLAG_GRANT_READ_URI_PERMISSION
のみを付与します。
個人を特定できる情報(PII)などのセンシティブ データは、アプリケーション コンテナやシステム認証情報ストレージ以外に保存しないでください。したがって、保存や共有される情報が機密でないことを明示的に確認した場合を除き、<external-path>
要素は使用しないでください。
リソース
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2024-02-23 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"]],["最終更新日 2024-02-23 UTC。"],[],[],null,["# Improperly Exposed Directories to FileProvider\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-STORAGE: Storage](https://mas.owasp.org/MASVS/05-MASVS-STORAGE)\n\nOverview\n--------\n\nAn improperly configured `FileProvider` can unintentionally expose files and directories to an attacker. Depending on the configuration, an attacker can read from or write to these exposed files, which in turn can lead to the exfiltration of sensitive information or, in the worst case, arbitrary code execution. For example, an application with `\u003croot-path\u003e` set in the configuration could enable an attacker to access sensitive information stored in databases or to overwrite the application's native libraries, leading to arbitrary code execution.\n\nImpact\n------\n\nThe impact varies depending on the configuration and file content, but generally leads to data leakage (when reading) or overwriting (when writing) files.\n\nMitigations\n-----------\n\n### Do not use the \\\u003croot-path\\\u003e path element in the configuration\n\n`\u003croot-path\u003e` corresponds to the root directory of the device (`/`). Allowing this in the configuration provides arbitrary access to files and folders, including the app's sandbox and `/sdcard` directory, which offers a very broad attack surface to an attacker.\n\n### Share narrow path ranges\n\nIn the path configuration file, avoid sharing a broad path range like `.` or `/`. Doing so can lead to exposing sensitive files by mistake. Share only a limited/narrower path range and ensure only files you want to share are under this path. This will prevent exposing sensitive files by mistake.\n\nA typical configuration file with safer settings could look like this: \n\n### Xml\n\n \u003cpaths\u003e\n \u003cfiles-path name=\"images\" path=\"images/\" /\u003e\n \u003cfiles-path name=\"docs\" path=\"docs\" /\u003e\n \u003ccache-path name=\"cache\" path=\"net-export/\" /\u003e\n \u003c/paths\u003e\n\n### Check and validate the external URIs\n\nValidate the external URIs (using a `content` scheme) and ensure they are not pointing to your application's local files. This prevents any inadvertent information leak.\n\n### Grant minimum access permissions\n\nA [`content URI`](/guide/topics/providers/content-provider-basics#ContentURIs) can have both read and write access permissions. Ensure only the minimum required access permission is granted.\nFor example, if *only* read permission is required, then explicitly grant only [`FLAG_GRANT_READ_URI_PERMISSION`](/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION).\n\n### Avoid usage of \\\u003cexternal-path\\\u003e for storing/sharing sensitive information\n\nSensitive data, like personally identifiable information (PII), should not be stored outside of the application container or system credential storage facilities. Thus, avoid the usage of the`\u003cexternal-path\u003e` element, unless you have explicitly verified that the information being stored/shared is not sensitive.\n\nResources\n---------\n\n- [FileProvider Documentation](/reference/androidx/core/content/FileProvider)\n\n- [Vulnerability on using \\\u003croot-path\\\u003e](https://hackerone.com/reports/876192)"]]