Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Transport Security has blocked a cleartext HTTP resource

Tags:

ios

socket.io

enter image description here

I am using Socket.IO library in swift and I keep getting this error:

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.

when I am trying to send an http request. I added the keys to plist according to the official apple documentation, but it did not help.

like image 582
Narek Simonyan Avatar asked Sep 24 '15 12:09

Narek Simonyan


People also ask

What is app transport security in Swift?

App Transport Security (ATS) lets an app add a declaration to its Info.plist. file that specifies the domains with which it needs secure communication. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt.

What is Application Transport Security?

App Transport Security (ATS) is an iOS feature that forces mobile apps to connect to back-end servers using HTTPS, instead of HTTP, to encrypt data in transit. ATS enforces a minimum security level for communications between a mobile app and web services that support its functionality.

What is Nsallowsarbitraryloads?

A Boolean value indicating whether App Transport Security restrictions are disabled for all network connections.


2 Answers

You need to correct it like this:

enter image description here

To make it easier, this is the correct xml in the info.plist

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>

change the localhost to your actual server

Check the table for NSAppTransportSecurity options

If you want to all communications with any domain, you can do this:

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

However, you should use the latest just in the developing phase.

like image 93
William Kinaan Avatar answered Oct 21 '22 22:10

William Kinaan


Another way to solve this, which I found more convenient, is to disable App Transport Security by default using the NSAllowsArbitraryLoads key. So any domains you do not include in the NSExceptionDomains dictionary (or if you don't include NSExceptionDomains at all) will not be subject to App Transport Security.

enter image description here

like image 42
strwils Avatar answered Oct 22 '22 00:10

strwils