[GH-ISSUE #154] Duplicate records when use URLProtocol to modify authorization header and ssl pinning challenge #93

Closed
opened 2026-03-03 19:11:45 +03:00 by kerem · 3 comments
Owner

Originally created by @HoaPham98 on GitHub (Nov 7, 2024).
Original GitHub issue: https://github.com/ProxymanApp/atlantis/issues/154

Originally assigned to: @NghiaTranUIT on GitHub.

Hi, I have a problems with atlantis when run it in the app that use URLProtocol. Because the app is blackbox so I can't show the code, but I can reproduce it with my guess code

import SwiftUI
import Foundation

final class MyProtocol: URLProtocol {
    override class func canInit(with request: URLRequest) -> Bool {
        if request.allHTTPHeaderFields?["Custom-Header"] == "Test value" {
            return false
        }
        return true
    }
    
    override class func canonicalRequest(for request: URLRequest) -> URLRequest {
        var request = request
        request.addValue("Test value", forHTTPHeaderField: "Custom-Header")
        return request
    }
    
    override func startLoading() {
        URLSession.shared.dataTask(with: request) { data, response, error in
            if let error {
                self.client?.urlProtocol(self, didFailWithError: error)
            } else if let response {
                self.client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
                if let data {
                    self.client?.urlProtocol(self, didLoad: data)
                }
            }
            self.client?.urlProtocolDidFinishLoading(self)
        }.resume()
    }
    
    override func stopLoading() {
        
    }
}

struct ContentView: View {
    
    private let session: URLSession
    
    init() {
        URLProtocol.registerClass(MyProtocol.self)
        let config = URLSessionConfiguration.default
        config.protocolClasses = [MyProtocol.self]
        session = URLSession(configuration: config)
    }
    
    var body: some View {
        VStack {
            Button("Httpbin") {
                Task {
                    do {
                        let (_, response) = try await session.data(from: URL(string:"https://httpbin.org/get")!)
                        print(response)
                    } catch {
                        print(error)
                    }
                }
            }
        }
        .padding()
    }
}```

When I run this code, and tap to Httpbin, Atlantis will capture 2 records, one has "Custom-Header", one not
Originally created by @HoaPham98 on GitHub (Nov 7, 2024). Original GitHub issue: https://github.com/ProxymanApp/atlantis/issues/154 Originally assigned to: @NghiaTranUIT on GitHub. Hi, I have a problems with atlantis when run it in the app that use URLProtocol. Because the app is blackbox so I can't show the code, but I can reproduce it with my guess code ``` swift import SwiftUI import Foundation final class MyProtocol: URLProtocol { override class func canInit(with request: URLRequest) -> Bool { if request.allHTTPHeaderFields?["Custom-Header"] == "Test value" { return false } return true } override class func canonicalRequest(for request: URLRequest) -> URLRequest { var request = request request.addValue("Test value", forHTTPHeaderField: "Custom-Header") return request } override func startLoading() { URLSession.shared.dataTask(with: request) { data, response, error in if let error { self.client?.urlProtocol(self, didFailWithError: error) } else if let response { self.client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed) if let data { self.client?.urlProtocol(self, didLoad: data) } } self.client?.urlProtocolDidFinishLoading(self) }.resume() } override func stopLoading() { } } struct ContentView: View { private let session: URLSession init() { URLProtocol.registerClass(MyProtocol.self) let config = URLSessionConfiguration.default config.protocolClasses = [MyProtocol.self] session = URLSession(configuration: config) } var body: some View { VStack { Button("Httpbin") { Task { do { let (_, response) = try await session.data(from: URL(string:"https://httpbin.org/get")!) print(response) } catch { print(error) } } } } .padding() } }``` When I run this code, and tap to Httpbin, Atlantis will capture 2 records, one has "Custom-Header", one not
kerem 2026-03-03 19:11:45 +03:00
  • closed this issue
  • added the
    Done
    bug
    labels
Author
Owner

@NghiaTranUIT commented on GitHub (Nov 7, 2024):

@HoaPham98 thanks for the report. It looks like a bug.

May I ask: If you don't use URLProtocol, is the bug gone?

<!-- gh-comment-id:2461547910 --> @NghiaTranUIT commented on GitHub (Nov 7, 2024): @HoaPham98 thanks for the report. It looks like a bug. May I ask: If you don't use URLProtocol, is the bug gone?
Author
Owner

@NghiaTranUIT commented on GitHub (Nov 7, 2024):

I'm able to reproduce the bug, let me find a way to fix it 👍

<!-- gh-comment-id:2461576046 --> @NghiaTranUIT commented on GitHub (Nov 7, 2024): I'm able to reproduce the bug, let me find a way to fix it 👍
Author
Owner

@HoaPham98 commented on GitHub (Nov 7, 2024):

@HoaPham98 thanks for the report. It looks like a bug.

May I ask: If you don't use URLProtocol, is the bug gone?

Yes. If I don't use URLProtocol, the bus is gone. And I have an idea for this issue. Hope you like to check it: https://github.com/ProxymanApp/atlantis/pull/155

<!-- gh-comment-id:2461797966 --> @HoaPham98 commented on GitHub (Nov 7, 2024): > @HoaPham98 thanks for the report. It looks like a bug. > > May I ask: If you don't use URLProtocol, is the bug gone? Yes. If I don't use URLProtocol, the bus is gone. And I have an idea for this issue. Hope you like to check it: https://github.com/ProxymanApp/atlantis/pull/155
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/atlantis#93
No description provided.