ناامن X509TrustManager
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
دسته OWASP: MASVS-CODE: کیفیت کد
نمای کلی
کلاس X509TrustManager
مسئول تأیید صحت یک سرور راه دور است. این کار را با تایید گواهی سرور انجام می دهد.
اجرای ناامن X509TrustManager
در یک برنامه اندروید، پیاده سازی است که صحت سروری را که برنامه با آن در ارتباط است به درستی تأیید نمی کند. این می تواند به مهاجم اجازه دهد تا جعل هویت یک سرور قانونی را بسازد و برنامه را فریب دهد تا داده های حساس را برای مهاجم ارسال کند.
این آسیبپذیری وجود دارد زیرا با استفاده از کلاس X509TrustManager
، Java/Android اجازه میدهد تا تأیید کامل سرور را لغو کند. کلاس X509TrustManager
دو عملکرد مورد علاقه دارد: checkServerTrusted()
و getAcceptedIssuers()
. این فراخوانی های تابع را می توان به گونه ای پیکربندی کرد که به همه گواهی های X.509 اعتماد کند. در نهایت، منطق اعتبارسنجی سفارشی ممکن است باگ یا ناقص باشد و اجازه اتصالات غیرمنتظره را بدهد. در تمام این موارد، هدف کلاس نفی شده است و اتصال شبکه ایجاد شده بر اساس خروجی X509TrustManager
ایمن نیست.
تاثیر
اجرای ناامن X509TrustManager می تواند منجر به آسیب پذیری هایی شود که می تواند برای انجام حملات MitM (Man-in-the-Middle) بر روی ترافیک شبکه از برنامه قربانی استفاده شود. تأثیر سوء استفاده از این کد ناامن این است که در صورت راه اندازی این کد، داده های شبکه برنامه کاربر می تواند توسط مهاجمان شبکه (از راه دور یا محلی) در معرض خطر قرار گیرد. این تأثیر به محتوای ترافیک شبکه بستگی دارد که به طور ناخواسته در معرض نمایش قرار می گیرد (PII، اطلاعات خصوصی، مقادیر حساس جلسه، اعتبار خدمات، و غیره).
اقدامات کاهشی
از عملکرد NetworkSecurityConfig.xml استفاده کنید تا اطمینان حاصل کنید که تمام اتصالات مرحله تولید، آزمایش، اشکال زدایی و توسعه به درستی به جای استفاده یا پیاده سازی کد تأیید اعتبار گواهی TLS/SSL سفارشی انجام می شود. اگر برای ساختهای آزمایشی و اشکالزدایی به استفاده از گواهی امضا شده نیاز است، به جای اجرای X509TrustManager
سفارشی، از NetworkSecurityConfig استفاده کنید.
منابع
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],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"]]