10

I cannot disable App Transport Security (ATS) in Xcode 9.2. I have been (for years) disabling ATS when running builds against my local server environment like so:

Transport security has blocked a cleartext HTTP

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

In Xcode 9.2, a simple request (running against a local Rails app in http mode):

let session = URLSession(configuration: .default)
let url = URL(string: "http://store.dev/api/products.json")!

let task = session.dataTask(with: url) { data, response, error in
    print(data)
    print(response)
    print(error)
}

task.resume()

fails with the error message

Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9802, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x60c00024afb0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://store.dev/api/products.json, NSErrorFailingURLStringKey=https://store.dev/api/products.json, _kCFStreamErrorDomainKey=3}

This exact same request (same project as well) succeeds on Xcode 9.1.

In both cases, I'm building against a iOS 11.1 deployment target. You can see that Xcode is changing the url from http to https, which I do not want.

Here is a link to the super basic project that works in Xcode 9.1 but fails in 9.2 (https://github.com/chrismanderson/ats-sample).

I've also tried disabling ATS just for the local store.dev domain, and again, it works on Xcode 9.1 but not 9.2.

4

2 回答 2

8

我最初并没有把它放在一起,但我认为正在发生的事情是,在 iOS 11 中,Apple 正在支持HSTS。我相信对 HSTS 预加载列表的支持,再加上 Google 最近将 .dev TLD 添加到 HSTS 预加载列表,可能会导致 iOS 尝试强制您使用 https,这是失败的(我错过了您尝试使用用于测试的 .dev 本地域,这确实是这里的关键元素)。

我认为您唯一的解决方案是将本地测试域更改为 .dev 域以外的域。如果您这样做,您应该能够连接,并且它不会试图强制您在本地开发环境中使用 https。

简而言之,Google 已经获得了 .dev 顶级域的权利,并且最近将其添加到 HSTS 预加载列表中,以强制所有与 .dev 域的通信都是安全的。在支持 HSTS 预加载列表的设备上,这会导致所有流量通过 HTTPS 重定向,这将在不支持 HTTPS 的服务器上导致错误。

于 2017-12-07T15:42:27.790 回答
0

在 XCode 屏幕左侧的导航器上,单击您的主项目文件,其中存储了所有文件和文件夹。单击信息选项卡。在“自定义 iOS 目标属性”下,您曾经看到更改应用程序传输安全设置 (ATS) 的选项。它没有明确说明,但仍然可用。

当您将鼠标悬停在选项上时,您应该会看到+一个小圆圈。点击它。XCode 将提示您创建一个“应用程序类别”。在出现的列表中,向上滚动并选择“应用程序传输安全设置”。

单击该选项。一旦创建,它应该提示您更改 BOOL 值(默认应该是“NO”)。在最右侧,您应该会看到一组向上和向下箭头。单击此按钮将 BOOL 更改为 yes。

于 2018-02-11T01:38:38.910 回答