createPackageContext
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
OWASP 카테고리: MASVS-CODE: 코드 품질
개요
public abstract Context createPackageContext (String packageName, int flags)
createPackageContext
메서드는 개발자가 자체 애플리케이션에서 다른 애플리케이션의 컨텍스트를 만들려는 경우에 사용됩니다.
예를 들어 개발자가 서드 파티 애플리케이션에서 리소스를 가져오거나 서드 파티 애플리케이션에서 메서드를 호출하려면 createPackageContext
를 사용합니다.
그러나 애플리케이션이 CONTEXT_IGNORE_SECURITY
및 CONTEXT_INCLUDE_CODE
플래그를 사용하여 createPackageContext
를 호출한 다음 getClassLoader()
를 호출하면 애플리케이션이 악성 애플리케이션의 코드 실행에 취약해질 수 있습니다. 예를 들어 공격자가 개발자가 사용자 기기에 있을 것으로 예상한 소유권 주장이 제기되지 않은 패키지 이름 (패키지 스쿼팅)을 명의 도용하면 이러한 상황이 발생할 수 있습니다.
애플리케이션이 이러한 종류의 공격에 취약해지려면 충족해야 하는 기준을 요약하면 다음과 같습니다.
취약한 앱:
악성 앱:
영향
애플리케이션에서 createPackageContext를 안전하지 않은 방식으로 사용하면 악성 애플리케이션이 취약한 애플리케이션의 컨텍스트에서 임의의 코드를 실행할 수 있습니다.
완화 조치
꼭 필요한 경우가 아니라면 CONTEXT_IGNORE_SECURITY
및 CONTEXT_INCLUDE_CODE
를 사용하여 createPackageContext
를 호출하지 마세요.
불가피한 경우 createPackageContext
를 실행하는 패키지의 ID를 확인하는 메커니즘을 구현해야 합니다 (예: 패키지 서명을 확인).
리소스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 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,["# createPackageContext\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\n public abstract Context createPackageContext (String packageName, int flags)\n\nThe method [`createPackageContext`](/reference/android/content/Context#createPackageContext(java.lang.String,%20int)) is used when a developer wants to create\na context for another application in their own application.\n\nFor example, if developers want to get resources from a 3rd-party application or\ncall methods from it, they would use `createPackageContext`.\n\nHowever, if an application calls `createPackageContext` with the\n[`CONTEXT_IGNORE_SECURITY`](/reference/android/content/Context#CONTEXT_IGNORE_SECURITY) and [`CONTEXT_INCLUDE_CODE`](/reference/android/content/Context#CONTEXT_INCLUDE_CODE) flags, and then\ncalls [`getClassLoader()`](/reference/android/content/Context#getClassLoader()), this could result in making the application\nvulnerable to code execution by a malicious application. This can occur, for\nexample, when an attacker impersonates an unclaimed package name (package\nsquatting) that the developer had expected to be present on the user's device.\n\nTo summarize the criteria that have to be met to make an application vulnerable\nto this kind of attack:\n\nVulnerable App:\n\n- Calls [`createPackageContext`](/reference/android/content/Context#createPackageContext(java.lang.String,%20int)) with [`CONTEXT_IGNORE_SECURITY`](/reference/android/content/Context#CONTEXT_IGNORE_SECURITY) and [`CONTEXT_INCLUDE_CODE`](/reference/android/content/Context#CONTEXT_INCLUDE_CODE).\n- Calls [`getClassLoader()`](/reference/android/content/Context#getClassLoader()) on the retrieved context.\n\nMalicious App:\n\n- Is able to claim the package name that the vulnerable app passes to [`createPackageContext`](/reference/android/content/Context#createPackageContext(java.lang.String,%20int)).\n- Exports android:appComponentFactory.\n\nImpact\n------\n\nWhen createPackageContext is used in an insecure way by an application, this can\nlead to a malicious application being able to gain arbitrary code execution in\nthe context of the vulnerable application.\n\nMitigations\n-----------\n\nDon't call [`createPackageContext`](/reference/android/content/Context#createPackageContext(java.lang.String,%20int)) with\n[`CONTEXT_IGNORE_SECURITY`](/reference/android/content/Context#CONTEXT_IGNORE_SECURITY) and [`CONTEXT_INCLUDE_CODE`](/reference/android/content/Context#CONTEXT_INCLUDE_CODE) unless absolutely necessary.\n\nIn cases where this is unavoidable, make sure to implement a mechanism to verify\nthe identity of the package you are executing [`createPackageContext`](/reference/android/content/Context#createPackageContext(java.lang.String,%20int)) on (e.g. by verifying the package's signature).\n\nResources\n---------\n\n- [createPackageContext Documentation](/reference/android/content/Context#createPackageContext(java.lang.String,%20int))\n- [OverSecured blog post on createPackageContext code execution](https://blog.oversecured.com/Android-arbitrary-code-execution-via-third-party-package-contexts)"]]