How can I add NSAppTransportSecurity to my info.plist file?
Asked Answered
H

13

149

https://developer.apple.com/videos/wwdc/2015/?id=711 @5:55

I can't seem to be able to add this to my info.plist. There is no value it. I'm running XCode Version 7.0 beta (7A121l), and testing on iOS9.

Because I can't specifically declare what URL's I want as seen in the video, I keep getting "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" errors.

However, I don't seem to be able to configure it. Any ideas?

Hussey answered 4/7, 2015 at 4:4 Comment(3)
You don't really have a question anymore, you should just go ahead and answer your own question and then accept after the appropriate time delay.Redolent
what is a domain name ? is this a server base url or any other ? and where to find my app domain name ?Panicstricken
Domain name is one of the most common term used . Well this is one which is bought and then after hosting you can use it as server base url which you use for API's. There is nothing like app domain name. So you can use the domain name as the one where API's are written.Dulaney
D
149

try With this --- worked for me in Xcode-beta 4 7.0

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourdomain.com</key>
        <dict>
            <!--Include to allow subdomains-->
            <key>NSIncludesSubdomains</key>
            <true/>
            <!--Include to allow HTTP requests-->
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <!--Include to specify minimum TLS version-->
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>

Also one more option, if you want to disable ATS you can use this :

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

But this is not recommended at all. The server should have the SSL certificates and so that there is no privacy leaks.

Dulaney answered 25/7, 2015 at 5:46 Comment(3)
I have XCode 7.2 (7C68) and I have modified (by disabling completely ATS) the info.plist of my test project. But it is not working. Any clue?Zachar
generally it does work... can you paste ur code here and then we can seeDulaney
And also if you have two or more domanis you have to add <key>NSAllowsArbitraryLoads</key> <true/><key>NSExceptionDomains</key> Otherwise for me it didn't work for release version for some reasonSybaris
B
111

You have to add just the NSAllowsArbitraryLoads key to YES in NSAppTransportSecurity dictionary in your info.plist file.

For example,

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

enter image description here

Bis answered 24/9, 2015 at 6:44 Comment(1)
This is a workaround. The real issue is death with in @Ashish's answerAlcoholism
A
49

That wasn't working for me, but this did the trick:

<key>NSAppTransportSecurity</key>  
     <dict>  
          <key>NSAllowsArbitraryLoads</key><true/>  
     </dict>  
Axiom answered 25/7, 2015 at 18:51 Comment(4)
I think you mean <true/> instead of <YES/>This
From security point of view, this is exactly a way, how NOT to do it, because nobody will ever review this section of code and update it to properly specified domains.Reitman
This is not a good practice. Rather we should allow specific domains.Dulaney
For other newbies like me: Make sure to put this at the correct position (at the end, enclosed by the existing </dict> and </plist> tags:Alible
I
25

Just to clarify ... You should always use httpS

But you can bypass it adding the exception:

enter image description here

Inhalant answered 17/9, 2015 at 19:19 Comment(0)
S
13

Xcode 8.2, iOS 10

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
Sutlej answered 15/12, 2016 at 8:32 Comment(0)
S
4

Update Answer (after wwdc 2016):

IOS apps will require secure HTTPS connections by the end of 2016

App Transport Security, or ATS, is a feature that Apple introduced in iOS 9. When ATS is enabled, it forces an app to connect to web services over an HTTPS connection rather than non secure HTTP.

However, developers can still switch ATS off and allow their apps to send data over an HTTP connection as mentioned in above answers. At the end of 2016, Apple will make ATS mandatory for all developers who hope to submit their apps to the App Store. link

Streetman answered 15/6, 2016 at 8:56 Comment(1)
after end of this year, new app or update app without using https will be rejected. what about existing app with the bypass ? (we need a force update ?)Streetman
T
3
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>com</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>net</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>org</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

This will allow to connect to .com .net .org

Terrijo answered 20/12, 2015 at 12:34 Comment(1)
Thank you for an example showing how to add multiple domains.Cragsman
S
3
<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>uservoice.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
Subsequent answered 13/7, 2016 at 8:51 Comment(0)
K
3

Open your info.plist file of your project with any editor of your preference, then add this code at the end of the file before the last

<key>NSAppTransportSecurity</key>
<dict>
   <key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Knightly answered 20/10, 2020 at 8:19 Comment(0)
H
2

In mac shell command line , use the following command:

plutil -insert NSAppTransportSecurity -xml "<array><string> hidden </string></array>" [location of your xcode project]/Info.plist 

The command will add all the necessary values into your plist file.

Holden answered 18/12, 2016 at 14:4 Comment(0)
A
1

To explain a bit more about ParaSara's answer: App Transport security will become mandatory and trying to turn it off may get your app rejected.

As a developer, you can turn App Transport security off if your networking code doesn't work with it, and you want to continue other development before fixing any problems. Say in a team of five, four can continue working on other things while one fixes all the problems. You can also turn App Transport security off as a debugging tool if you have networking problems and you want to check if they are caused by App Transport security. As soon as you know you should turn it on again immediately.

The solution that you must use in the future is not to use http at all, unless you use a third party server that doesn't support https. If your own server doesn't support https, Apple will have a problem with that. Even with third party servers, I wouldn't bet that Apple accepts it.

Same with the various checks for server security. At some point Apple will only accept justifiable exceptions.

But mostly, consider this: You are endangering the privacy of your customers. That's a big no-no in my book. Don't do that. Fix your code, don't ask for permission to run unsafe code.

Anomalous answered 15/6, 2016 at 9:9 Comment(0)
R
1

One bad news for developers using NSAppTransportSecurity.

UPDATE:
[Apple will require HTTPS connections for iOS apps by the end of 2016]

https://techcrunch.com/2016/06/14/apple-will-require-https-connections-for-ios-apps-by-the-end-of-2016/

Rodney answered 16/6, 2016 at 7:52 Comment(0)
P
1

XCODE 8, Swift 3: You need to add a row: **

"App transport Security Setting"

** in the info.plist inside information Property list.

Pianola answered 21/1, 2017 at 19:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.