App Transport Security 通过自定义 url 方案阻止路由

App Transport Security blocks routing via custom url scheme

我的 iOS 应用程序(用 Swift 和 React Native 编写)有一个自定义 url 方案,允许我从例如像这样的 Safari myappscheme://https://www.mywebsite.com/somematerial。如果我在我的应用程序中启用应用程序传输安全性,通过自定义 url 方案的路由将被阻止,我收到此消息:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

但是,如果我禁用 ATS,应用程序会按预期进行路由。我没有在我的应用程序中通过 http 访问任何 link,在我的路由中我总是通过 https 获取数据。因此,我不知道为什么 ATS 会阻止此路由。你知道我是否需要提供一些关于我的 url 方案的额外信息吗?

请在Info.plist中查看我的 ATS 配置:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

我也已将我的自定义 url 方案列入白名单:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>myappscheme</string>
</array>

我认为问题出在 React Native 上,你提到你使用 Safari 作为自定义链接的来源,这可能意味着你正在尝试在模拟器中调试你的应用程序和自定义路由,所以你的问题可能与反应本机。如果您在 React Native 离线工作时在真实设备上有相同的行为,请更新您的问题。

Temporarily disable App Transport Security (ATS) by adding the NSAllowsArbitraryLoads entry to your Info.plist file. Since ATS does not allow insecure HTTP requests to IP addresses, you must completely disable it to run on a device. This is only a requirement for development on a device, and unless you can't workaround an issue you should leave ATS enabled for production builds. For more information, see this post on configuring ATS.

React Native Documentation - Running On Device

配置 info.plist 设置。

您可以添加特定域,例如:

<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>www.google.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>

此问题已解决。我注销了我正在点击的端点,并通过在终端中执行以下操作检查它是否满足 ATS 要求:

nscurl --ats-diagnostics https://www.example.com/

事实证明,我尝试获取的特定子域未满足所有 ATS 要求。我的服务器团队已解决该问题并使端点安全。