onevcat / Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.
MIT License
23.14k stars 2.65k forks source link

No trust evaluation handling after receiving the authentication challenge #2263

Open vsonawane-csod opened 3 months ago

vsonawane-csod commented 3 months ago

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

During our projects security scan, we have received a bug related to Manual Server Trust Authentication Attempts which can cause vulnerability in the app by providing a window for the man-in-middle attack.

What

The security scan shows the below evidence that exposes the URL and also it doesn't seem to perform any kind of trust evaluation after delegate method:

func urlSession(
        _ session: URLSession,
        didReceive challenge: URLAuthenticationChallenge
    ) async -> (URLSession.AuthChallengeDisposition, URLCredential?)

Here is the trace:

{
  "class": "KFSessionDelegate",
  "connectingTo": "our_url_here",
  "firstMethod": "- URLSession:didReceiveChallenge:completionHandler:",
  "secondMethod": "NSURLSessionAuthChallengeUseCredential"
} 

Other Comment

Can you please let me know how to deal with this?

onevcat commented 3 months ago

Kingfisher implements these delegate methods in the image downloader and again delegates them out again to allow library users to customize their own logic. By default, as long as you didn't provide your implementation or set the trustedHosts, a .performDefaultHandling and an nil URLCredential is returned, so I don't see an issue in Kingfisher's implementation.

I am not sure what the issue you are facing now. If it is a warning from your security scan, then I believe it is a false positive and maybe it is better to ask the security scan support team to see if there is a way to prevent this.