How Should API Keys be Stored?

Mobile app developers keep hearing that they shouldn’t store API keys in their app code but they don’t hear where they should store them. In this article we discuss the topic and provide some practical solutions.

API keys are unique digital identifiers that authenticate requests to the API from a remote client such as a mobile app and are typically used to control API access; they can also be used for identification, rate limiting and billing purposes. Unfortunately, API keys are often inadequately protected and can easily be exploited in a number of ways:

  1. Mobile apps can be downloaded from app stores by anyone,reverse engineered and the keys extracted.
  2. API keys may be accidentally exposed through public code sharing sites such as GitHub.
  3. A Man-in-the-Middle attack can be performed to intercept the traffic between a mobile app and backend API and steal API keys and other secrets.

Risks of exposed API keys

Depending on the functionality of the API and the permissions associated with it, there are a number of risks to your business if your API key becomes available to bad actors:

Securing API Keys

To prevent accidentally exposing API keys to the public, it would obviously be best to avoid embedding them directly in the app’s source code. However, this is non-trivial to achieve because the mobile app needs to transmit the API key to the API backend. Here are some approaches which could be considered:

Exit mobile version