首页 文章

iOS App Transport Security阻止来自例外域的http转移

提问于
浏览
0

我'm trying to configure ATS to allow http loads from my domain, but with the plist settings below it is still blocking access to image requests (but strangely, not to http ' POST'消息) . 如果我启用允许任意负载,它工作正常 . 获取图像的代码使用NSURLConnection sendAsynchronousRequest和(例如)http://www.my-domain.com/ImageStore/aFolder/bfolder/xyz.jpg的url . 我正在使用最新更新从模拟器运行 . 我找不到其他人报告类似的问题......我做错了什么?

警告信息:

App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全 . 可以通过应用程序的Info.plist文件配置临时例外 .

info.plist设置:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>my-domain.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubDomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>

1 回答

  • 1

    您正在为NSAppTransportSecurity正确设置全局设置 . 我已经包含了一个适用于我的应用程序的版本 .

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>my-domain.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    

    来自iOS 9.0的发行说明

    应用程序传输安全应用程序传输安全性(ATS)在应用程序及其后端之间的安全连接中实施最佳实践 . ATS防止意外泄露,提供安全的默认行为,并且易于采用;它在iOS 9和OS X v10.11中默认也是打开的 . 无论您是创建新应用程序还是更新现有应用程序,都应尽快采用ATS . 如果您正在开发新应用,则应该专门使用HTTPS . 如果您有现有应用,则应尽可能多地使用HTTPS,并创建一个计划,以便尽快迁移其余应用 . 此外,您通过更高级别的API进行的通信需要使用具有前向保密性的TLS 1.2版进行加密 . 如果尝试 Build 不符合此要求的连接,则会引发错误 . 如果您的应用需要向不安全的域发出请求,则必须在应用的Info.plist文件中指定此域 .

    Apple's WWDC video与NSURLSession联网也提到了ATS

相关问题