בקרת גישה מבוססת-הרשאות לרכיבים שמיוצאים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
קטגוריה ב-OWASP: MASVS-PLATFORM: Platform Interaction
סקירה כללית
הרשאה של Android היא מזהה מחרוזת שהוצהר במניפסט של האפליקציה כדי לבקש גישה לפעולות או לנתונים מוגבלים, שנאכפת בזמן הריצה על ידי מסגרת Android.
רמות ההרשאות ב-Android מציינות את הסיכון הפוטנציאלי שמשויך להרשאה:
- רגילות: הרשאות עם סיכון נמוך, שמוענקות באופן אוטומטי בזמן ההתקנה
- מסוכנות: הרשאות בסיכון גבוה שעלולות לאפשר גישה לנתונים רגישים של משתמשים, שמחייבות אישור מפורש של המשתמש בזמן הריצה
- חתימה: מוענקת רק לאפליקציות חתומות עם אותו אישור כמו האפליקציה שמצהירה על ההרשאה. בדרך כלל ההרשאה הזו משמשת לאפליקציות מערכת או לאינטראקציות בין אפליקציות של אותו מפתח
נקודות חולשה שקשורות לאמצעי בקרת גישה שמבוססים על הרשאות מתרחשות כשהרכיב של האפליקציה (כמו פעילות, מקלט, ספק תוכן או שירות) עומד בכל הקריטריונים הבאים:
- הרכיב לא משויך לאף
android:permission
ב-Manifest
.
- הרכיב מבצע משימה רגישה שעבורה קיימת הרשאה שהמשתמש כבר אישר.
- הרכיב מיוצא.
- הרכיב לא מבצע בדיקות הרשאה ידניות (ברמת המניפסט או ברמת הקוד).
במקרה כזה, אפליקציה זדונית יכולה לבצע פעולות רגישות על ידי ניצול לרעה של ההרשאות של הרכיב הפגיע, והעברת ההרשאות של האפליקציה הפגיעה לאפליקציה הזדונית.
השפעה
אפשר להשתמש בייצוא של רכיבים נחשפים כדי לקבל גישה למשאבים רגישים או לבצע פעולות רגישות. ההשפעה של ההתנהגות הלא רצויה הזו תלויה בהקשר של הרכיב הפגיע ובהרשאות שלו.
מיטיגציות
דרישה להרשאות לביצוע משימות רגישות
כשמייצאים רכיב עם הרשאות רגישות, צריך לתת את אותן ההרשאות לכל בקשה נכנסת. סביבת הפיתוח המשולבת (IDE) של Android Studio כוללת בדיקות איתור שגיאות בקוד (lint) למקלטים ולשירותים כדי לזהות את נקודת החולשה הזו ולהמליץ על הצורך בהרשאות המתאימות.
מפתחים יכולים לדרוש הרשאות לבקשות נכנסות על ידי הצהרה עליהן בקובץ Manifest
או ברמת הקוד במהלך הטמעת השירות, כמו בדוגמאות הבאות.
XML
<manifest ...>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application ...>
<service android:name=".MyExportService"
android:exported="true"
android:permission="android.permission.READ_CONTACTS" />
</application>
</manifest>
Kotlin
class MyExportService : Service() {
private val binder = MyExportBinder()
override fun onBind(intent: Intent): IBinder? {
// Enforce calling app has the required permission
enforceCallingPermission(Manifest.permission.READ_CONTACTS, "Calling app doesn't have READ_CONTACTS permission.")
// Permission is enforced, proceed with export logic
return binder
}
// Inner class for your Binder implementation
private inner class MyExportBinder : Binder() {
// Permission is enforced, proceed with export logic
}
}
Java
public class MyExportService extends Service {
@Override
public IBinder onBind(Intent intent) {
// Enforce calling app has the required permission
enforceCallingPermission(Manifest.permission.READ_CONTACTS, "Calling app doesn't have READ_CONTACTS permission.");
return binder;
}
// Inner class for your Binder implementation
private class MyExportBinder extends Binder {
// Permission is enforced, proceed with export logic
}
}
לא מייצאים את הרכיב
הימנעו מייצוא רכיבים שיש להם גישה למשאבים רגישים, אלא אם יש צורך חיוני בכך. כדי לעשות זאת, צריך להגדיר את android:exported
בקובץ Manifest
כ-false
עבור הרכיב. החל מרמת API 31 ואילך, המאפיין הזה מוגדר כברירת מחדל לערך false
.
XML
<activity
android:name=".MyActivity"
android:exported="false"/>
החלת הרשאות המבוססות על חתימה
כשמשתפים נתונים בין שתי אפליקציות שבבעלותכם או בשליטתכם, צריך להשתמש בהרשאות שמבוססות על חתימות. ההרשאות האלה לא מחייבות אישור מהמשתמש, ובמקום זאת הן בודקות שהאפליקציות שגולשות בנתונים חתומים באמצעות אותו מפתח חתימה.
ההגדרה הזו מספקת חוויית משתמש מאובטחת ופשוטה יותר. אם מגדירים הרשאות בהתאמה אישית, חשוב להביא בחשבון את ההנחיות המתאימות לאבטחה.
XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<permission android:name="my_custom_permission_name"
android:protectionLevel="signature" />
נקודות קצה למשימות בודדות
מטמיעים את האפליקציה בהתאם לעיקרון העיצוב הפרדת הבעיות. כל נקודת קצה צריכה לבצע רק קבוצה קטנה של משימות ספציפיות עם הרשאות ספציפיות. שיטת העיצוב הזו מאפשרת למפתח גם להחיל הרשאות מפורטות לכל נקודת קצה. לדוגמה, מומלץ לא ליצור נקודת קצה אחת שמשמשת גם את היומן וגם את אנשי הקשר.
משאבים
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת 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,["# Permission-based access control to exported components\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-PLATFORM: Platform Interaction](https://mas.owasp.org/MASVS/09-MASVS-PLATFORM)\n\nOverview\n--------\n\nAn Android permission is a string identifier declared in the app's manifest to\nrequest access to restricted data or actions, enforced at runtime by the Android\nframework.\n\n[Android permission levels](/guide/topics/manifest/permission-element#plevel) indicate the potential risk associated with the\npermission:\n\n- **Normal**: Low-risk permissions, automatically granted at install time\n- **Dangerous**: High-risk permissions that could allow access to sensitive user data, requiring explicit user approval at runtime\n- **Signature**: Granted only to apps signed with the same certificate as the app declaring the permission, typically used for system apps or interactions between apps from the same developer\n\nVulnerabilities related to permission-based access controls occur when an app's\ncomponent (such as [activity](/reference/android/app/Activity), [receiver](/privacy-and-security/security-tips#broadcast-receivers), [content provider](/privacy-and-security/security-tips#content-providers), or\n[service](/privacy-and-security/security-tips#services)) meets all of the following criteria:\n\n- The component is not associated with any `android:permission` in the `Manifest`;\n- The component performs a sensitive task for which a permission exists that the user has already approved;\n- The component is exported;\n- The component does not perform any manual (manifest or code-level) permission checks;\n\nWhen this happens, a malicious app can perform sensitive actions by abusing the\nprivileges of the vulnerable component, proxying the vulnerable app's privileges\nto the malicious app.\n\nImpact\n------\n\nExporting vulnerable components can be used to gain access to sensitive\nresources or to perform sensitive actions. The impact of this unwanted behavior\ndepends on the context of the vulnerable component and its privileges.\n\nMitigations\n-----------\n\n### Require permissions for sensitive tasks\n\nWhen exporting a component with sensitive permissions, require those same\npermissions for any incoming request. The Android Studio IDE has lint checks for\n[receivers](https://googlesamples.github.io/android-custom-lint-rules/checks/ExportedReceiver.md.html) and [services](https://googlesamples.github.io/android-custom-lint-rules/checks/ExportedService.md.html) to spot this\nvulnerability and recommend requiring the appropriate permissions.\n\nDevelopers can require permissions for incoming requests either by declaring\nthem in the `Manifest` file or at code-level when implementing the service, as\nin the following examples. \n\n### Xml\n\n \u003cmanifest ...\u003e\n \u003cuses-permission android:name=\"android.permission.READ_CONTACTS\" /\u003e\n\n \u003capplication ...\u003e\n \u003cservice android:name=\".MyExportService\"\n android:exported=\"true\"\n android:permission=\"android.permission.READ_CONTACTS\" /\u003e\n\n \u003c/application\u003e\n \u003c/manifest\u003e\n\n### Kotlin\n\n class MyExportService : Service() {\n\n private val binder = MyExportBinder()\n\n override fun onBind(intent: Intent): IBinder? {\n // Enforce calling app has the required permission\n enforceCallingPermission(Manifest.permission.READ_CONTACTS, \"Calling app doesn't have READ_CONTACTS permission.\")\n // Permission is enforced, proceed with export logic\n return binder\n }\n\n // Inner class for your Binder implementation\n private inner class MyExportBinder : Binder() {\n // Permission is enforced, proceed with export logic\n }\n }\n\n### Java\n\n public class MyExportService extends Service {\n\n @Override\n public IBinder onBind(Intent intent) {\n // Enforce calling app has the required permission\n enforceCallingPermission(Manifest.permission.READ_CONTACTS, \"Calling app doesn't have READ_CONTACTS permission.\");\n\n return binder;\n\n }\n\n // Inner class for your Binder implementation\n private class MyExportBinder extends Binder {\n // Permission is enforced, proceed with export logic\n\n }\n }\n\n### Don't export the component\n\nAvoid exporting components with access to sensitive resources unless absolutely\nnecessary. You can achieve this by setting the `android:exported` in the\n`Manifest` file to `false` for your component. From [API level 31](/about/versions/12/behavior-changes-12#exported) and\nbeyond, this attribute is set to `false`by default. \n\n### Xml\n\n \u003cactivity\n android:name=\".MyActivity\"\n android:exported=\"false\"/\u003e\n\n### Apply signature-based permissions\n\nWhen sharing data between two apps that you control or own, use signature-based\npermissions. These permissions don't require user confirmation and, instead,\ncheck that the apps accessing the data is signed using the same signing key.\nThis setup offers a more streamlined, secure user experience. If you declare\ncustom permissions do consider the [corresponding security guidelines](https://developer.android.com/privacy-and-security/risks). \n\n### Xml\n\n \u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"com.example.myapp\"\u003e\n \u003cpermission android:name=\"my_custom_permission_name\"\n android:protectionLevel=\"signature\" /\u003e\n\n### Single-task endpoints\n\nImplement your app by following the [Separation of Concerns](/topic/architecture#separation-of-concerns) design\nprinciple. Each endpoint should only perform a small set of specific tasks with\nspecific privileges. This good design practice also allows the developer to\napply granular permissions for each endpoint. For example, avoid creating a\nsingle endpoint that serves both calendar and contacts.\n\nResources\n---------\n\n- [Android Access to app protected components from the Oversecured blog](https://blog.oversecured.com/Android-Access-to-app-protected-components/)\n- [Content Provider Best Practices](/privacy-and-security/security-tips#content-providers)\n- [Runtime (Dangerous) Permissions](/guide/topics/permissions/overview#runtime)\n- [Separation of Concerns design principle](/topic/architecture#separation-of-concerns)\n- [Android permissions documentation](/guide/topics/manifest/permission-element#plevel)\n- [Android broadcast receivers security tips](/privacy-and-security/security-tips#broadcast-receivers)\n- [Android services security tips](/privacy-and-security/security-tips#services)\n- [Android 12 (API 31) exported default set to \"false\"](/about/versions/12/behavior-changes-12#exported)\n- [Lint Check: Exported PreferenceActivity shouldn't be exported](https://googlesamples.github.io/android-custom-lint-rules/checks/ExportedPreferenceActivity.md.html)\n- [Lint Check: Exported Receiver doesn't require permission](https://googlesamples.github.io/android-custom-lint-rules/checks/ExportedReceiver.md.html)\n- [Lint Check: Exported Service doesn't require permission](https://googlesamples.github.io/android-custom-lint-rules/checks/ExportedService.md.html)"]]