
Dulob584278 (Community Member) asked a question.
I have the following code to specifically validate host in trust validation
and in the end of the custom certs validation I still go for the default validation by iOS as it follows
and I still get Improper Validation of Certificate with Host Mismatch CWE ID 297
Can someone advise on what exactly needs to be in the code to satisfy this check?
.png)
Hi @Dulob584278 (Community Member) ,
Veracode Static Analysis will report CWE 297 Improper Validation of Certificate with Host Mismatch when it can see that a credential is provided to the completionHandler that sets serverTrust.
This is typically done to ignore any errors related to TLS and may allow an attacker to pretend to be the destination of the URL if they are able to execute a Man In The Middle attack.
We recommend removing this code. Please note that ".performDefaultHandling" will ignore any credential provided so the code relating to the credential and it's setup can safely be removed.
Thank you,
Boy Baukema
Thanks for the reply. Just to make sure I properly understand the response above. Does it mean that the following code will report CWE 297?
let credential: URLCredential = URLCredential(trust: serverTrust)
completionHandler(.useCredential, credential)
I would like a clarification here as well. Will ANY call to
completionHandler(.useCredential, credential)
trigger a flaw?