X509TrustManager غير آمن
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
فئة OWASP: MASVS-CODE: جودة الرمز
نظرة عامة
فئة X509TrustManager
مسؤولة عن التحقّق من صحة خادم بعيد. ويتم ذلك من خلال التحقّق من صحة شهادة الخادم.
إنّ تنفيذ X509TrustManager
غير آمن في أحد تطبيقات Android هو تنفيذ لا يتحقّق بشكل صحيح من صحة الخادم الذي يتواصل معه التطبيق. ويمكن أن يسمح ذلك للمهاجم بانتحال هوية خادم شرعي وخداع التطبيق لإرسال بيانات حساسة إليه.
تحدث الثغرة الأمنية بسبب استخدام الفئة X509TrustManager
،
حيث يسمح Java/Android بتجاوز عملية التحقّق من الخادم بالكامل. تتضمّن الفئة
X509TrustManager
دالتَين مهمتَين:
checkServerTrusted()
وgetAcceptedIssuers()
. يمكن ضبط عمليات استدعاء الدالة هذه للوثوق بجميع شهادات X.509. أخيرًا، قد تكون منطق التحقّق المخصّص من الصحة معطّلاً أو غير مكتمل، ما يسمح بحدوث اتصالات غير متوقّعة.
في كل هذه الحالات، تم إلغاء الغرض من الفئة، كما أنّ اتصال الشبكة الذي تم إنشاؤه استنادًا إلى الناتج X509TrustManager
ليس آمنًا.
التأثير
يمكن أن تؤدي عمليات التنفيذ غير الآمنة لواجهة X509TrustManager إلى حدوث ثغرات أمنية يمكن استخدامها لتنفيذ هجمات وسيطة على حركة بيانات الشبكة من التطبيق المستهدف. ويتمثّل تأثير استغلال هذا الرمز غير الآمن في إمكانية تعرُّض بيانات شبكة التطبيق الخاصة بالمستخدمين للاختراق من قِبل مهاجمي الشبكة (عن بُعد أو محليًا) في حال تفعيل هذا الرمز. يعتمد التأثير على محتوى زيارات الشبكة التي تم الكشف عنها عن غير قصد (معلومات تحديد الهوية الشخصية، والمعلومات الخاصة، وقيم الجلسات الحسّاسة، وبيانات اعتماد الخدمة، وما إلى ذلك).
إجراءات التخفيف
استخدِم وظيفة NetworkSecurityConfig.xml للتأكّد من أنّه يتم التعامل مع جميع الاتصالات في مراحل الإنتاج والاختبار وتصحيح الأخطاء والتطوير بشكل سليم، بدلاً من استخدام رمز مخصّص للتحقّق من صحة شهادة TLS/SSL أو تنفيذه. إذا كنت بحاجة إلى استخدام شهادة موقَّعة ذاتيًا في إصدارات الاختبار وتصحيح الأخطاء، ننصحك باستخدام NetworkSecurityConfig بدلاً من تنفيذ X509TrustManager
مخصّص.
المراجع
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Unsafe X509TrustManager\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nThe `X509TrustManager` class is responsible for verifying the authenticity of a\nremote server. It does this by validating the server's certificate.\n\nAn insecure `X509TrustManager` implementation in an Android application is an\nimplementation that does not properly verify the authenticity of the server with\nwhich the application is communicating. This can allow an attacker to\nimpersonate a legitimate server and trick the application into sending sensitive\ndata to the attacker.\n\nThe vulnerability exists because using the [`X509TrustManager`](/reference/javax/net/ssl/X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate%5B%5D,%20java.lang.String)) class,\nJava/Android allows the complete overriding of server verification. The\n`X509TrustManager` class has two functions of interest:\n[`checkServerTrusted()`](/reference/javax/net/ssl/X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate%5B%5D,%20java.lang.String)) and [`getAcceptedIssuers()`](/reference/javax/net/ssl/X509TrustManager#getAcceptedIssuers()). These function\ncalls can be configured to trust all X.509 certificates. Finally, custom\nvalidation logic may be buggy or incomplete and permit unexpected connections.\nIn all these cases, the purpose of the class has been negated and the network\nconnection established based on the `X509TrustManager` output is not secure.\n\nImpact\n------\n\nUnsafe X509TrustManager implementations can lead to vulnerabilities which can be\nused to perform MitM (Man-in-the-Middle) attacks on network traffic from the\nvictim application. The impact of exploiting this insecure code is that a user's\napplication network data can be compromised by network attackers (remotely or\nlocally) if this code is triggered. The impact is dependent on the content of\nthe network traffic being inadvertently exposed (PII, private information,\nsensitive session values, service credentials, etc).\n\nMitigations\n-----------\n\nUse the [NetworkSecurityConfig.xml](/training/articles/security-config) functionality to ensure that all\nproduction, testing, debugging, and dev stage connections are properly handled\nrather than using or implementing custom TLS/SSL certificate validation code. If\nusing a self-signed certificate is needed for test and debug builds, consider\nusing NetworkSecurityConfig instead of implementing a custom `X509TrustManager`.\n\nResources\n---------\n\n- [Play Warning docs](https://support.google.com/faqs/answer/6346016)\n- [Documentation to assist configuring the Network security configuration xml file.](/training/articles/security-config)\n- [Developer documentation for the TrustManager class.](/reference/javax/net/ssl/TrustManager)\n- [This check looks for X.509TrustManager implementations whose checkServerTrusted or checkClientTrusted methods do nothing (thus trusting any certificate chain).](https://googlesamples.github.io/android-custom-lint-rules/checks/TrustAllX509TrustManager.md.html)\n- [This check looks for custom X.509TrustManager implementations.](https://googlesamples.github.io/android-custom-lint-rules/checks/CustomX509TrustManager.md.html)\n- \u003chttps://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/X509TrustManagerDetector.java\u003e"]]