असुरक्षित HostnameVerifier
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
OWASP कैटगरी: MASVS-CODE: कोड क्वालिटी
खास जानकारी
HostnameVerifier
लागू करने की सुविधा यह पुष्टि करती है कि सर्वर के सर्टिफ़िकेट में मौजूद होस्टनेम, उस सर्वर के होस्टनेम से मेल खाता है जिससे क्लाइंट कनेक्ट करने की कोशिश कर रहा है.
Android ऐप्लिकेशन में HostnameVerifier को असुरक्षित तरीके से लागू करने का मतलब है कि ऐप्लिकेशन, उस सर्वर के होस्टनेम की पुष्टि सही तरीके से नहीं करता है जिससे वह संपर्क कर रहा है. इससे हमलावर, किसी मान्य सर्वर के नाम पर काम कर सकता है. साथ ही, ऐप्लिकेशन को गुमराह करके, संवेदनशील डेटा भेजने के लिए कह सकता है.
यह जोखिम इसलिए है, क्योंकि HostnameVerifier
क्लास में ऐसे फ़ंक्शन कॉल हैं जो X.509 सर्टिफ़िकेट के होस्टनेम की पुष्टि को छोड़ सकते हैं. इसके बजाय, वे सिर्फ़ सर्टिफ़िकेट के हैश की पुष्टि कर सकते हैं. आम तौर पर, यह गलतफ़हमी होती है कि SSLSession#isValid
फ़ंक्शन, सुरक्षा से जुड़ा कोई काम करता है. हालांकि, असल में इसका मकसद सिर्फ़ यह जांचना होता है कि कोई सेशन मान्य है या नहीं और उसे फिर से शुरू करने या उसमें शामिल होने के लिए उपलब्ध है या नहीं. इनमें से कोई भी सेशन की सुरक्षा की पुष्टि नहीं करता. HostnameVerifier क्लास की जगह NetworkSecurityConfig ले लेगा.
असर
HostnameVerifier को असुरक्षित तरीके से लागू करने पर, ऐसी समस्याएं हो सकती हैं जिनका इस्तेमाल, एमआईटीएम (मैन-इन-द-मिडल) हमले करने के लिए किया जा सकता है. ये हमले, टारगेट किए गए ऐप्लिकेशन से आने वाले नेटवर्क ट्रैफ़िक पर किए जाते हैं. इस असुरक्षित कोड का गलत इस्तेमाल करने पर, नेटवर्क पर हमला करने वाले लोग या ग्रुप, उपयोगकर्ता के ऐप्लिकेशन के नेटवर्क डेटा को रिमोट या लोकल तौर पर ऐक्सेस कर सकते हैं. ऐसा तब होता है, जब यह कोड ट्रिगर हो जाता है. इसका असर इस बात पर निर्भर करता है कि अनजाने में कौनसा नेटवर्क ट्रैफ़िक ज़ाहिर हुआ है. जैसे, व्यक्तिगत पहचान से जुड़ी जानकारी (पीआईआई), निजी जानकारी, संवेदनशील सेशन वैल्यू, सेवा के क्रेडेंशियल वगैरह.
जोखिम कम करने के तरीके
NetworkSecurityConfig.xml का इस्तेमाल करके, यह पक्का करें कि कस्टम TLS/एसएसएल सर्टिफ़िकेट की पुष्टि करने वाले कोड का इस्तेमाल करने या लागू करने के बजाय, सभी प्रोडक्शन, टेस्टिंग, डीबगिंग, और डेवलपमेंट स्टेज कनेक्शन सही तरीके से मैनेज किए जाएं.
संसाधन
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. 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,["# Unsafe HostnameVerifier\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 [`HostnameVerifier`](/reference/javax/net/ssl/HostnameVerifier#verify(java.lang.String,%20javax.net.ssl.SSLSession)) implementation is responsible for verifying that the\nhostname in the server's certificate matches the hostname of the server that the\nclient is trying to connect to.\n\nAn unsafe HostnameVerifier implementation in an Android application is an\nimplementation that does not properly verify the hostname 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\nThis vulnerability exists because the `HostnameVerifier` class has function\ncalls that can skip X.509 certificate hostname validation and, instead, only\nverify the hash of the certificate. A common misconception is that the\n[`SSLSession#isValid`](/reference/javax/net/ssl/SSLSession#isValid()) function performs a security-related operation, when\nin reality its purpose is only to check if a session is valid and available for\nresuming or joining; neither of which validate the *security* of a session. The\nHostnameVerifier class has been superseded by [NetworkSecurityConfig](/training/articles/security-config).\n\nImpact\n------\n\nUnsafe HostnameVerifier 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) 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.\n\nResources\n---------\n\n- [Network Security Configuration Documentation](/training/articles/security-config)\n- [This check looks for implementations of HostnameVerifier whose verify method always returns true (thus trusting any hostname)](https://googlesamples.github.io/android-custom-lint-rules/checks/BadHostnameVerifier.md.html)\n- [Developer documentation for the HostnameVerifier class](/reference/javax/net/ssl/HostnameVerifier#verify(java.lang.String,%20javax.net.ssl.SSLSession))\n- [AllowAllHostnameVerifierDetector class in Android](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AllowAllHostnameVerifierDetector.java)"]]