Skip to content

Instantly share code, notes, and snippets.

@flpwgr
Created September 15, 2015 14:44
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flpwgr/6e73a3d52607288f64b5 to your computer and use it in GitHub Desktop.
Save flpwgr/6e73a3d52607288f64b5 to your computer and use it in GitHub Desktop.
Cordova Hook for App Transport Security iOS 9
#!/bin/bash
PLIST=platforms/ios/*/*-Info.plist
cat << EOF |
Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES
EOF
while read line
do
/usr/libexec/PlistBuddy -c "$line" $PLIST
done
true
@hammady
Copy link

hammady commented Sep 19, 2015

Please don't set arbitrary loads to true, this will probably end in the rejection of your app. It is better to add exceptions per domain. Please see this stackoverflow answer: http://stackoverflow.com/a/30732693/441849

@fi5u
Copy link

fi5u commented Sep 22, 2015

How could this be modified to add exceptions per domain?

@nextrealm
Copy link

Change:

Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES

To:

Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSExceptionDomains dict
Add :NSAppTransportSecurity:NSExceptionDomains:example.com dict
Add :NSAppTransportSecurity:NSExceptionDomains:example.com:NSIncludesSubdomains bool YES
Add :NSAppTransportSecurity:NSExceptionDomains:example.com:NSExceptionAllowsInsecureHTTPLoads bool YES

Where example.com is the domain you want to whitelist

@digitalcatnip
Copy link

My app will be allowing users to enter a domain to connect to my custom Node.js server they would install. Is that a good exception to the App Transport Security feature? I have custom logic to verify they are connected to a port running my service and not some random HTTP apache host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment