bug: config.xml being re-sorted, breaking STA correct
Type: bug
Platform: ios 9 webview
This is the current state of the section:
<config-file platform="ios" target="*-Info.plist" parent="NSAppTransportSecurity">
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>devcdb</key>
<key>localhost</key>
<dict>
<key>NSIncludesSubdomains</key>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<true/>
</dict>
<dict>
<key>NSIncludesSubdomains</key>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<true/>
</dict>
</dict>
</dict>
</config-file>
This was the original contents before the build:
<config-file platform="ios" target="*-Info.plist" parent="NSAppTransportSecurity">
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>devcdb</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>localhost</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</config-file>
This behavior was not seen a few days ago, so likely occurred in a recent upgrade. I use an after_prepare hook to update my plist with this code -- which worked very well until this point.
Is this a bug? Or is it a feature and I'll have to find another method to update my plist with this information?
How did you cause this re-sorting? There's nothing that I know of that would cause this. Still the original snippet you had was off a bit.
https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/
For each url that you want to work with, you need a separate block for exceptions.
How did I cause the resorting? You joke!
Frankly, I have no idea how it happened. I only know that it happened while I was building the project using ionic build ionic emulate iOS and building the project in Xcode. The only thing I added to the build process is the script that added them to the plist -- which I copied from here: https://gist.github.com/marcocarnazzo/6f01a57d390e8fe3071f -- now that I think about it, the script itself might be the cause of the problem -- bears testing.
However, in the interim I've switched to a PlistBuddy based solution.
'a separate block for exceptions' -- you mean, two blocks with key NSExceptionDomains one for each domain? Interesting, it's a plural, so that's a bit surprising. Especially since it works the way it is. Thanks for the heads up.
Not that you caused it, but how could I go and attempt to recreate the issue.
If you're using that script, you should know that it requires a few node modules as well. I have isolated the script in a npm package that you can use.
https://github.com/mhartington/cordova-config-utils
As for the exceptions,

While NSExceptionDomains may be able to accept multiple domains, each of the domains needs a separate block for it should be handled. Easy way to think of it is that NSExceptionDomains is an array, and each domain is an object that you can configure, only in XML
I have the same issue. I can reproduce it by calling
ionic emulate ios --livereload
ionic-cli seems to reformat config.xml when called with "--livereload". It than changes the <content> tag, deletes all comments and reorders (and destroys <dict>) entries.
Thanks for isolating this @rdavono. It's consistent with my experience, in that I'm sure that I emulated iOS with the livereload flag.
Interesting. Definitely a CLI issue. Closing here for now, mind creating an issue: https://github.com/driftyco/ionic-cli/issues?
ionic-app-lib issue in config-xml.js:
https://github.com/driftyco/ionic-app-lib/issues/105