Search code examples
iossecurityenvironment-variablesapi-keygoogle-books

Should I worry about my API Keys being extracted from the iOS app


I need to make requests to the Google Books API form my app which includes the API key in the URL.

I thought about just creating it as file private variable in my app, though this is a big problem because it would then be uploaded to Github.

Then I thought about environment variables but I heard they aren't included if the app isn't run by Xcode.

I'm aware that this way the key could be extracted, but should I worry? Can't users anyway just use Wireshark or something similar and see the key in the URL?

And I can restrict the key so it is only valid when called from my Bundle ID.

What do you think would be the best option for making the calls? I mean other than that, the app barely gets 10 downloads a week so this can't be too big of an issue, right?


Solution

  • Whether it is an issue entirely depends on your usecase and threat model. Consider your api key public if you include or send it in any way in/from your app, and think about things like what can people do with it. What level of harm can they cause you? This gives yo the impact. Would they be motivated, for example is there a financial benefit for them somehow? This estimates the likelihood of this happening. This together, impact x likelihood = risk, which you can either accept (do nothing about it), mitigate (decrease the impact or likelihood), eliminate (fix it) or transfer (rg. buy some kind of an insurance).

    As for mitigations, can you limit the api key scope, so that only necessary things can be done on the api with it? Can you set up rate limiting? Monitoring, alerting? I'm not familiar with the Books api, but these could be mitigating controls.

    As for eliminating the risk, you should not put the api key in the app. You could set up your own server, which would hold the api key, and would pretty much forward requests to theBooks api, augmented with thr api key. Note though that you would still need some kind of authentication and access control in your server, otherwise it can just be used as an oracle by an attacker to perform anything in the actual Books api the same as if they had the key, only in this case they don't need it. This role could also be fulfilled by some kind of an api gateway, which can also add data to api queries.

    Eliminating the risk is obviously more expensive. Defenses should be proportionate to risk, so you have to decide whether it is worth it.