android:exported
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
OWASP 類別:MASVS-PLATFORM:平台互動
總覽
android:exported
屬性可設定活動、服務、廣播接收器等元件能否由其他應用程式的元件啟動:
- 如果設為
true
,任何應用程式皆可存取活動,並以確切的類別名稱啟動活動。
- 如果設為
false
,則只有同一個應用程式的元件、具有相同使用者 ID 的應用程式,或具備特殊權限的系統元件,才能啟動活動。
這個屬性預設值背後的邏輯經過了演變,會因元件類型和 Android 版本而異。舉例來說,在 API 級別 16 (Android 4.1.1) 以下版本中,<provider>
元素會預設為 true
。如未明確設定這個屬性,可能會導致某些裝置採用不同的預設值。
影響
如果預設值不同,可能會不小心公開應用程式內部元件。以下列舉幾個可能的後果:
發生阻斷服務攻擊。其他應用程式不當存取內部元件,修改應用程式內部功能。機密資料外洩。在有安全漏洞的應用程式中執行程式碼。
因應措施
請一律明確設定 android:exported
屬性。這樣一來,就不會留下任何解釋空間,且能針對元件的瀏覽權限明確指出您的意圖。
為您推薦
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2024-01-05 (世界標準時間)。
[null,null,["上次更新時間:2024-01-05 (世界標準時間)。"],[],[],null,["# android:exported\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-PLATFORM: Platform Interaction](https://mas.owasp.org/MASVS/09-MASVS-PLATFORM)\n\nOverview\n--------\n\nThe `android:exported` [attribute](/guide/topics/manifest/activity-element#exported) sets whether a component (activity, service, broadcast receiver, etc.) can be launched by components of other applications:\n\n- If `true`, any app can access the activity and launch it by its exact class name.\n- If `false`, only components of the same application, applications with the same user ID, or privileged system components can launch the activity.\n\nThe logic behind the default value of this attribute changed over time and was different depending on the component types and Android versions. For example, on API level 16 (Android 4.1.1) or lower the value for `\u003cprovider\u003e` elements is set to `true` by default. Not setting this attribute explicitly carries the risk of having different default values between some devices.\n\nImpact\n------\n\nThe situation with different default values means you could accidentally expose internal application components. A few examples of the consequences could be the following:\n\nDenial of service attacks.\nOther apps inappropriately accessing internal components to modify your app's internal functionality.\nLeaking of sensitive data.\nCode execution in the context of the vulnerable application.\n\nMitigations\n-----------\n\nAlways explicitly set the `android:exported` attribute. This will leave no room for interpretation and clearly signal your intention with regard to a component's visibility.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [# Key management {:#key-management}](/topic/security/data)\n- [Run embedded DEX code directly from APK](/topic/security/dex)\n- [Tapjacking](/topic/security/risks/tapjacking)"]]