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 확인 및 유효성 검증하기
외부 URI(content
스키마 사용)의 유효성을 검증하고 다시 한번 확인하여 URI가 애플리케이션의 로컬 파일을 가리키지 않도록 합니다. 이렇게 하면 실수로 정보가 유출되는 것을 방지할 수 있습니다.
액세스 권한은 최소한으로만 부여하기
content URI
에는 읽기 및 쓰기 액세스 권한이 모두 포함될 수 있습니다. 최소한의 필수 액세스 권한만 부여되었는지 확인합니다.
예를 들어 읽기 권한만 필요한 경우에는 명시적으로 FLAG_GRANT_READ_URI_PERMISSION
만 부여합니다.
개인 식별 정보(PII)와 같은 민감한 정보를 애플리케이션 컨테이너 또는 시스템 사용자 인증 정보 저장소 시설 외부에 저장하면 안 됩니다. 따라서 저장/공유되는 정보가 민감한 정보가 아니라는 것을 명시적으로 확인하지 않은 한 <external-path>
요소를 사용하지 마세요.
리소스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2023-12-15(UTC)
[null,null,["최종 업데이트: 2023-12-15(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)"]]