Critical: Insecure SSL: Server Identity Verification Disabled(驗證憑證)
在.NET程式透過WebRequest來建立HTTPS或FTPS連線時,有時攻城獅可能因為無法確認憑證有效性,寫了 不理會憑證是否有效的程式碼來讓程式正常運作 ,上線前,送到源碼檢測健康檢查時,就會被列出來*標示Critical的風險,來還技術債吧。 建立HTTPS或FTPS連線時 --HTTPS HttpWebRequest WebRequest = (HttpWebRequest) System.Net.WebRequest.Create( " https://www.MyHomeWebSite.com " ); --FTPS FtpWebRequest request = (FtpWebRequest)WebRequest.Create( "ftp://192.168.1.1:21/FileFolder" ); 加上這句 System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true ; }; 又或者是 System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true ; }; 總之就是只想回傳true,但完全沒驗證,留下了技術債。 Insecure SSL: Server Identity Verification Disabled 好!如果這樣寫,交付客戶程式碼時,fortify會回報 Critical等級的 Insecure SSL: Server Identity Verification Disabled 的issue。 解決方式 修改的方式只要加上檢核,不管檢核的好或不好,像是檢核憑證發行者issuer不 可以是鋼鐵人 (誤, 應該是東尼・史塔克 )、效期、Subject是否包含domain網址等等....