简体   繁体   English

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

[英]App Transport Security blocks routing via custom url scheme

My iOS app (written in Swift and React Native) has a custom url scheme that allows me to route to the app from eg Safari like this myappscheme://https://www.mywebsite.com/somematerial . 我的iOS应用程序(用Swift和React Native编写)有一个自定义url方案,允许我从例如Safari这样的appappscheme:// https://www.mywebsite.com/somematerial路由到应用程序。 If I enable App Transport Security in my app, the routing via custom url scheme is blocked and I get this message: 如果我在我的应用中启用App Transport Security,则会阻止通过自定义网址方案进行路由,并收到以下消息:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全。 Temporary exceptions can be configured via your app's Info.plist file. 可以通过应用程序的Info.plist文件配置临时例外。

However, if I disable ATS, the app routes as expected. 但是,如果我禁用ATS,应用程序将按预期路由。 I am not accessing any link via http in my app and in my routing I always fetch data via https. 我没有通过我的应用程序中的http访问任何链接,在我的路由中,我总是通过https获取数据。 Therefore, I don't know why ATS is blocking this routing. 因此,我不知道为什么ATS会阻止此路由。 Do you know if I have to provide some additional info about my url scheme? 你知道我是否必须提供一些关于我的网址方案的其他信息吗?

Please see my ATS configurations in Info.plist: 请参阅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>

I've also whitelisted my custom url scheme: 我还将我的自定义网址列入白名单:

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

This issue has been resolved. 此问题已得到解决。 I logged out the endpoint I was hitting and checked if it satisfied ATS requirements by doing in Terminal: 我注销了我正在击中的端点,并检查它是否满足ATS要求,方法是在终端:

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

It turned out that the particular subdomain I was trying to fetch failed all ATS requirements. 事实证明,我试图获取的特定子域未能满足所有ATS要求。 My server team has fixed the issue and made the endpoint secure. 我的服务器团队修复了问题并使端点安全。

I think the problem is with React Native, you mentioned that you use Safari as a source for custom links and probably it means that you're trying to debug your app & custom routing in Simulator, so maybe your issue related to React Native. 我认为问题在于React Native,你提到你使用Safari作为自定义链接的来源,这可能意味着你试图在模拟器中调试你的应用程序和自定义路由,所以也许你的问题与React Native有关。 If you have the same behaviour on a real device when React Native works offline, then please update your question. 如果React Native脱机工作时在真实设备上具有相同的行为,请更新您的问题。

Temporarily disable App Transport Security (ATS) by adding the NSAllowsArbitraryLoads entry to your Info.plist file. 通过将NSAllowsArbitraryLoads条目添加到Info.plist文件暂时禁用App Transport Security(ATS)。 Since ATS does not allow insecure HTTP requests to IP addresses, you must completely disable it to run on a device. 由于ATS不允许对IP地址进行不安全的HTTP请求,因此必须完全禁用它才能在设备上运行。 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. 这只是在设备上进行开发的要求,除非您无法解决问题,否则应该为生产版本启用ATS。 For more information, see this post on configuring ATS. 有关更多信息,请参阅有关配置ATS的这篇文章

React Native Documentation - Running On Device 反应本机文档 - 在设备上运行

Configure info.plist setting. 配置info.plist设置。

You can add a specific domain like: 您可以添加以下特定域:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM