Dulob584278 (Community Member) asked a question.

CWE ID 297 flaw fix for iOS

I have the following code to specifically validate host in trust validation

imageand in the end of the custom certs validation I still go for the default validation by iOS as it follows

imageand 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?

 


  • 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

    Expand Post
    • Dulob584278 (Community Member)

      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)

  • CMaiorino723161 (Community Member)

    I would like a clarification here as well. Will ANY call to

    completionHandler(.useCredential, credential)

    trigger a flaw?

Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.