X509TrustManager לא מאובטח
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
קטגוריה ב-OWASP: MASVS-CODE: איכות הקוד
סקירה כללית
המחלקות X509TrustManager
אחראיות לאימות האותנטיות של שרת מרוחק. הוא עושה זאת על ידי אימות האישור של השרת.
הטמעה לא מאובטחת של X509TrustManager
באפליקציית Android היא הטמעה שלא מאמתת בצורה נכונה את האותנטיות של השרת שאיתו האפליקציה מתקשרת. זה יכול לאפשר לתוקף להתחזות לשרת לגיטימי ולגרום לאפליקציה לשלוח מידע רגיש לתוקף.
הפגיעות קיימת כי השימוש במחלקה X509TrustManager
, Java/Android מאפשר לבטל לחלוטין את אימות השרת. למחלקה
X509TrustManager
יש שתי פונקציות שחשובות לנו:
checkServerTrusted()
ו-getAcceptedIssuers()
. אפשר להגדיר את הקריאות לפונקציות כך שכל אישורי X.509 יהיו מהימנים. בנוסף, יכול להיות שיש באגים בלוגיקה של אימות מותאם אישית או שהיא לא שלמה, ולכן היא מאפשרת חיבורים לא צפויים.
בכל המקרים האלה, המטרה של המחלקה בוטלה והחיבור לרשת שנוצר על סמך הפלט של X509TrustManager
לא מאובטח.
השפעה
הטמעות לא בטוחות של X509TrustManager עלולות להוביל לנקודות תורפה שאפשר לנצל כדי לבצע התקפות מסוג MITM (אדם בתווך) על תנועת הרשת מאפליקציית הקורבן. ההשפעה של ניצול הקוד הלא מאובטח הזה היא שנתוני הרשת של האפליקציה של המשתמש עלולים להיפרץ על ידי תוקפים ברשת (מרחוק או באופן מקומי) אם הקוד הזה מופעל. ההשפעה תלויה בתוכן של תעבורת הרשת שנחשפה בטעות (פרטים אישיים מזהים, מידע פרטי, ערכי סשן רגישים, פרטי כניסה לשירותים וכו').
אמצעי צמצום סיכונים
כדי לוודא שכל החיבורים בשלבי הייצור, הבדיקה, הניפוי והפיתוח מטופלים בצורה נכונה, מומלץ להשתמש בפונקציונליות של NetworkSecurityConfig.xml במקום להשתמש בקוד אימות מותאם אישית של אישורי TLS/SSL או להטמיע אותו. אם יש צורך להשתמש באישור בחתימה עצמית בגרסאות בדיקה ובגרסאות לניפוי באגים, כדאי להשתמש ב-NetworkSecurityConfig במקום להטמיע X509TrustManager
בהתאמה אישית.
משאבים
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. 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,["# 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"]]