netfox icon indicating copy to clipboard operation
netfox copied to clipboard

Custom `URLSessionConfiguration.httpCookieStorage` is ignored

Open guillermomuntaner opened this issue 2 years ago • 0 comments

Describe the bug Custom URLSessionConfiguration.httpCookieStorage are not honored:

public extension Session {
    static let customSession: Session = {
        let sessionConfiguraton = URLSessionConfiguration.default
        sessionConfiguraton.protocolClasses?.insert(NFXProtocol.self, at: 0)
        sessionConfiguraton.httpCookieStorage = customCookieStorage
        return Session(configuration: sessionConfiguraton)
    }()
}

To Reproduce

  1. Use a custom httpCookieStorage. In our case, we use a HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: "groupname") to share cookies between app and extensions
  2. Plug netfox, do any request
  3. Cookies are not added from / saved to the expected httpCookieStorage

Expected behavior Cookies are get/set into the configured httpCookieStorage. Instead they seem to be saved into the default one.

Additional context My guess is that cookie handling happens in the URLProtocol implementation that the NFXProtocol shadows. Internally the NFXProtocol uses a URLSession(configuration: .default, ...) session which doesn't use the httpCookieStorage we want it to use.

I guess the solution is either or:

  1. (Ideally) Fix the NFXProtocol to use the httpCookieStorage. Unfortunately I am not familiar with URLProtocol so I don't know exactly what is missing here.
  2. (Probably good enought) Provide a way to configure the URLSession that NFXProtocol uses so we can configure it too

guillermomuntaner avatar Apr 21 '22 09:04 guillermomuntaner