ผู้ส่งของ Intent ที่รอดำเนินการ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หมวดหมู่ OWASP: MASVS-CODE: คุณภาพของโค้ด
ภาพรวม
การใช้ PendingIntent.getCreator*()
หรือ PendingIntent.getTarget*()
เพื่อพิจารณาว่าจะเชื่อถือผู้ส่ง PendingIntent หรือไม่จะทำให้เกิดความเสี่ยงในการถูกแสวงหาประโยชน์
PendingIntent.getCreator*()
หรือ
PendingIntent.getTarget*()
จะแสดงผู้สร้าง PendingIntent
ซึ่งไม่ตรงกับผู้ส่งเสมอไป แม้ว่าครีเอเตอร์อาจเป็นบุคคลที่เชื่อถือได้ แต่ไม่ควรเชื่อถือผู้ส่ง เนื่องจากผู้ส่งอาจเป็นแอปที่เป็นอันตราย
ซึ่งได้ PendingIntent ของแอปอื่นโดยใช้กลไกต่างๆ เช่น
ตัวอย่างการใช้ PendingIntent.getCreator*()
หรือ PendingIntent.getTarget*()
โดยชอบด้วยกฎหมายคือการแสดง
ไอคอนของแอปที่จะเริ่มต้นโดย PendingIntent
ผลกระทบ
การเชื่อถือผู้ส่ง PendingIntent เนื่องจากคุณได้ค้นหา (และเชื่อถือ) ครีเอเตอร์
อาจทำให้เกิดช่องโหว่ได้ หากแอปเชื่อถือผู้ส่ง PendingIntent ตามผู้สร้าง แล้วแชร์ตรรกะการตรวจสอบสิทธิ์หรือการให้สิทธิ์ เมื่อใดก็ตามที่ผู้ส่ง PendingIntent เป็นแอปที่เป็นอันตราย การดำเนินการนี้จะทำให้เกิดการข้ามการตรวจสอบสิทธิ์หรืออาจถึงขั้นมีการดำเนินการโค้ดจากระยะไกลโดยอิงตามอินพุตที่ไม่ถูกต้องและไม่น่าเชื่อถือ ทั้งนี้ขึ้นอยู่กับการใช้งานโค้ดของแอปพลิเคชันที่มีช่องโหว่
การลดปัญหา
แยกความแตกต่างระหว่างผู้ส่งกับครีเอเตอร์
ตรรกะการตรวจสอบสิทธิ์หรือการให้สิทธิ์ทุกประเภทที่ดำเนินการเมื่อได้รับ PendingIntent ต้องไม่ขึ้นอยู่กับสมมติฐานเกี่ยวกับผู้สร้าง PendingIntent ที่ระบุโดยใช้ PendingIntent.getCreator*()
หรือ PendingIntent.getTarget*()
ใช้วิธีอื่นในการตรวจสอบผู้โทร
หากต้องการตรวจสอบสิทธิ์ผู้โทร คุณควรใช้ Service หรือ ContentProvider แทนการใช้ PendingIntent เนื่องจากทั้ง 2 อย่างนี้อนุญาตให้ดึง UID ของผู้โทรด้วย Binder.getCallingUid() เมื่อคุณอยู่ในบริบทของการส่ง IPC ขาเข้า คุณจะค้นหา UID ได้ในภายหลังโดยใช้
PackageManager.getPackagesForUid()
อีกวิธีหนึ่งซึ่งใช้ได้ตั้งแต่ API ระดับ 34 คือการใช้
BroadcastReceiver.getSentFromUid() หรือ
BroadcastReceiver.getSentFromPackage() หากผู้ส่งเลือกที่จะแชร์
ข้อมูลประจำตัวระหว่างการออกอากาศโดยใช้ BroadcastOptions.isShareIdentityEnabled()
คุณควรตรวจสอบเสมอว่าแพ็กเกจที่เรียกใช้มีลายเซ็นตามที่คาดไว้ เนื่องจากแพ็กเกจที่โหลดด้านข้างอาจมีชื่อแพ็กเกจที่ซ้อนทับกับแพ็กเกจจาก Play Store
แหล่งข้อมูล
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 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-27 UTC"],[],[],null,["# Sender of Pending Intents\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nUsing [`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1) or [`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1) to determine whether to trust a PendingIntent's sender creates an\nexploitation risk.\n\n[`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1) or\n[`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1) returns the PendingIntent's\ncreator, which does not always match its sender. The creator may be trusted, but\nthe sender should **never** be trusted, as the sender might be a malicious app\nthat acquired another app's PendingIntent using a variety of mechanisms, for\nexample:\n\n- from [`NotificationListenerService`](/reference/android/service/notification/NotificationListenerService)\n- legitimate use cases that are part of the vulnerable app.\n\nAn example of a legitimate use of [`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1) or [`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1) would be to show\nthe icon of the app that will be started by the PendingIntent.\n\nImpact\n------\n\nTrusting a PendingIntent's sender because you queried (and trust) the creator\ncan lead to vulnerabilities. If an app trusts the PendingIntent's sender based\non its creator, and then shares its authentication or authorization logic, then\nwhenever the PendingIntent's sender is a malicious app, this would lead to an\nauthentication bypass or potentially even remote code execution based on\ninvalidated, untrusted input, depending on the implementation of the vulnerable\napplication's code.\n\nMitigations\n-----------\n\n### Distinguish between sender and creator\n\nAny type of authentication or authorization logic performed when receiving a\nPendingIntent must not be based on assumptions regarding the PendingIntent's\ncreator identified using either [`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1)\nor [`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1).\n\n### Use alternative ways to validate callers\n\nIf you need to authenticate the caller, instead of using PendingIntent, you\nshould use a Service or ContentProvider -- both allow fetching the caller UID\nwith [Binder.getCallingUid()](/reference/android/os/Binder#getCallingUid()) when you are in the context of dispatching an\nincoming IPC. The UID can be queried later by using\n[PackageManager.getPackagesForUid()](/reference/android/content/pm/PackageManager#getPackagesForUid(int)).\n\nAnother approach, available from API level 34, would be to use\n[BroadcastReceiver.getSentFromUid()](/reference/android/content/BroadcastReceiver#getSentFromUid()) or\n[BroadcastReceiver.getSentFromPackage()](/reference/android/content/BroadcastReceiver#getSentFromPackage()) if the sender opted in to sharing\nidentity during broadcast using [BroadcastOptions.isShareIdentityEnabled()](/reference/android/app/BroadcastOptions#isShareIdentityEnabled()).\n\nYou should always check if the calling package has the expected signature, as\nsideloaded packages can have package names overlapping with ones from the Play\nStore.\n\nResources\n---------\n\n- [Pending Intent](/reference/android/app/PendingIntent)"]]