Why must API keys be kept private

apiriskSecurity

I have worked with public API's in only one small project, but I recently learned that if one were to distribute a project with API keys inside this is a security risk.

So I have two questions:

  • What does an API key contain that would pose a security risk?
  • How does one create an application that makes use of public API's and
    distribute that application without posing a security risk?

Surely if someone can reverse engineer the application, they could extract any API keys that are present.

Best Answer

It depends on what the API key does. However, if the API key is giving you access to something or controlling your access to something, why would you want other people to piggyback on the resources that you have access to? You wouldn't.

Think about it this way. I own a service and you are a user of it, perhaps even a paying customer. I give you an API key based on an agreed upon level of service (perhaps API calls per unit of time). If this API key was public, other people could use it to pretend to be you and use up your limited API calls.

That's probably the least concerning situation. Sharing of API keys becomes more of a concern if the API key authenticates someone for access to a subset of data.

The methods of protecting API keys depends on the technology that you are using. When developing web or mobile applications, for example, you can help protect your API keys by ensuring they don't end up on the client (the web browser or the mobile device). Instead, they can remain on the servers used by the client. The client can authenticate against the services which can then make appropriate calls. Depending on the environment, the API keys can even be encrypted as they are stored in different environments.

Related Topic