Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load an HTTP URL with App Transport Security enabled in iOS 9? [duplicate]

So, the new beta SDK of iOS released last night has "App Transport Security" which encourages developers to use https instead of http. In principle, this is a great idea, and I already use https in our staging/production environments. However, I don't have https set up in my local development environment, when the iOS app is connecting to a web service I'm running on my laptop.

From a bit of playing around this morning, it appears that the URL loading system will, even if you hand it an http URL, decide to use https instead. Does anyone know how to disable this behaviour -- even just for particular URLs?

like image 215
Graeme Mathieson Avatar asked Jun 09 '15 12:06

Graeme Mathieson


People also ask

What is App transport security iOS?

App Transport Security (ATS) is a privacy feature introduced in iOS 9. It's enabled by default for new apps and enforces secure connections.

What is the required by ATS for the HTTP connections?

ATS requires that all HTTP connections made with the URL Loading System—typically using the NSURLSession class—use HTTPS. It further imposes extended security checks that supplement the default server trust evaluation prescribed by the Transport Layer Security (TLS) protocol.

What is App transport security in iOS Swift?

ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt. You should adopt ATS as soon as possible, regardless of whether you're creating a new app or updating an existing one. If you're developing a new app, you should use HTTPS exclusively.

Do Iphone apps use HTTP?

Apple will require all apps to enforce ATS, which will force the connections to HTTPS instead of HTTP. For those unfamiliar, HTTPS is simply the secure version of HTTP (Hypertext Transfer Protocol), the protocol for data communication online.


2 Answers

See Apple’s Info.plist reference for full details (thanks @gnasher729).

You can add exceptions for specific domains in your Info.plist:

<key>NSAppTransportSecurity</key> <dict>     <key>NSExceptionDomains</key>     <dict>         <key>testdomain.com</key>         <dict>             <key>NSIncludesSubdomains</key>             <true/>             <key>NSExceptionAllowsInsecureHTTPLoads</key>             <true/>             <key>NSExceptionRequiresForwardSecrecy</key>             <true/>             <key>NSExceptionMinimumTLSVersion</key>             <string>TLSv1.2</string>             <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>             <false/>             <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>             <true/>             <key>NSThirdPartyExceptionMinimumTLSVersion</key>             <string>TLSv1.2</string>             <key>NSRequiresCertificateTransparency</key>             <false/>         </dict>     </dict> </dict> 

All the keys for each excepted domain are optional. The speaker did not elaborate on any of the keys, but I think they’re all reasonably obvious.

(Source: WWDC 2015 session 703, “Privacy and Your App”, 30:18)

You can also ignore all app transport security restrictions with a single key, if your app has a good reason to do so:

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

If your app does not have a good reason, you may risk rejection:

Setting NSAllowsArbitraryLoads to true will allow it to work, but Apple was very clear in that they intend to reject apps who use this flag without a specific reason. The main reason to use NSAllowsArbitraryLoads I can think of would be user created content (link sharing, custom web browser, etc). And in this case, Apple still expects you to include exceptions that enforce the ATS for the URLs you are in control of.

If you do need access to specific URLs that are not served over TLS 1.2, you need to write specific exceptions for those domains, not use NSAllowsArbitraryLoads set to yes. You can find more info in the NSURLSesssion WWDC session.

Please be careful in sharing the NSAllowsArbitraryLoads solution. It is not the recommended fix from Apple.

— kcharwood (thanks @marco-tolman)

like image 145
8 revs, 3 users 93% Avatar answered Sep 23 '22 08:09

8 revs, 3 users 93%


As accepted answer has provided required info, and for more info about using and disabling App Transport Security one can find more on this.

For Per-Domain Exceptions add these to the Info.plist:

<key>NSAppTransportSecurity</key> <dict>   <key>NSExceptionDomains</key>   <dict>     <key>yourserver.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> 

But What If I Don’t Know All the Insecure Domains I Need to Use? Use following key in your Info.plist

<key>NSAppTransportSecurity</key> <dict>   <!--Include to allow all connections (DANGER)-->   <key>NSAllowsArbitraryLoads</key>       <true/> </dict> 

For more detail you can get from this link.

like image 29
Akshay Sunderwani Avatar answered Sep 21 '22 08:09

Akshay Sunderwani