macOS\iOS App Transport Security Error in FMX

May 6th, 2020 Posted by Embarcadero No Comment yet

Recently we were updating a system we had built for one of our customers. One of the things we needed to do was update the macOS applications for 64bit.

There are 3 applications in the suite that support macOS, and the first two converted very smoothly thanks to the 64bit macOS support in RAD Studio 10.3.3. Pretty much all that was needed was a recompile and to run them through the automated test suite.

However, the third one was a little trickier, so I wanted to document it here for anyone (including me) who strikes it in future.

I need to give a little context about what this particular app does. It allows their users to create template files that are then used to automatically generate config files used by a few of their internal systems and equipment. The Templates are just text files, but embedded in them are tags that they can use to pull in data from different sources: files on disk, a database, from one of their internal systems, even a http(s) url.

This particular app compiled no problems, and even passed tests with a few different templates we had setup. However one template, the one that included a tag to pull in data from an external http URL, failed, triggering the following error:

Error -1022 accessing to http://someaddress/somefile.xml: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

I’ve changed the URL to protect the innocent, but after a bit of digging it turns out that macOS v10.11 (and also iOS 9.0) introduced a new default security policy that prevents applications accessing http urls (ie. not https).

Unfortunately the customer didn’t control all the URLs they needed to pull data from, and indeed some were not using https. So we needed to change this policy for this app.

In the Apple world, you typically do this sort of thing through the info.plist file in your Application Bundle. Apple’s docs do a reasonable job of outlining the changes you need to make. Combine this with Embarcadero’s docs on changing your Info.plist and it was relatively straight forward, once we knew what was going on.

In the Project directory you’ll find an info.plist.TemplateOSX.xml file, which is the template RAD Studio will use to create your info.plist file.

We needed to edit this to add the additional keys needed to enable HTTP access. Now, if it had been possible, I’d have preferred to whitelist the specific insecure URLs they needed. That is supported by Apple, so we could allow these two or three URLs, and not any others. However, in this case the customer couldn’t predict ahead of time which URLs they would need. They varied depending on their clients, so we were left with having to turn on HTTP access altogether. I don’t recommend this, unless it’s really needed and your user fully understands the consequences. Also be aware, that if you are looking at deploying via the App Store, Apple’s review process will look closely at these security settings and may reject if they feel the loosening of the defaults is not justified.

OK, warnings out of the way, our info.plist.TemplateOSX.xml file ended up looking like this:

With that change and a recompile, our macOS tests all passed.

As mentioned above, according to the docs this also affects iOS, and should be fixed in mostly the same way. However, we haven’t hit this issue on our mobile projects yet, so can’t confirm.

Tags: , , , , , ,

No comments yet. You should be kind and add one!

Leave a Reply