API key meaning, in plain words

An API key is a long passphrase showing a caller may use a service. How OWASP says to use and protect it, why hard-coding is risky, and its limits.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

An API key is a long passphrase that shows a caller has been allowed to use a service. An API is the entry point through which apps and services call each other's functions, and the key goes with the request sent to that entry point. OWASP explains that it is used to curb the danger of a public API with no limits being overused and the cost swelling.

How does an API key work?

Imagine handing a business partner an entry pass that carries a member number. Only the person who shows the pass gets through reception. An API key is likewise handed to the side that uses the service, and attached to every call.

According to OWASP's guidance, an entry point you want to protect asks for the key on every request. For a caller who sends too many requests, it returns the error 429 (too many requests). The key of a caller who breaks the rules is revoked.

One use you can imagine is that issuing a separate key for each partner makes it easier to hold down overuse partner by partner. It is a secret string, but its role differs from a user's own login. The temporary pass issued after login is explained in access token. Failures in API authentication are gathered in API authentication flaws. For help with how you handle keys, contact us.

Why does an API key matter?

If an API key leaks, people other than the owner can call the API. OWASP says not to rely only on API keys to protect important resources. It also writes that a key handed to a third party leaks comparatively easily.

A typical route for leaks is writing it into code. MITRE's CWE-798 classifies as a weakness the fixed embedding of credentials such as passwords and encryption keys in a product. Real cases of leaks are explained in access key leaks. The basics of handling keys are these.

  • Do not put them in the URL. They remain in server logs, and OWASP treats a form like ?apiKey= as a bad example.
  • For retrieval requests (GET), send them in an HTTP header.
  • Do not write them directly in source code or a shared repository.
  • When you learn one has leaked, revoke it at once and make a new one.
  • Do not allow important operations on the key alone. Layer another check.
  • Keep a list of whom you gave a key to and for what use.

Related terms

  • Access token: a temporary pass issued after login
  • JWT: a document that makes proof of login portable
  • Cryptographic failures: a flaw where information that must be protected is not encrypted enough
  • OAuth: a mechanism for giving another app permission without handing over the password

Frequently asked questions

Can an API key alone protect an API?

It is not enough. OWASP says not to rely on API keys alone to protect sensitive information or important resources, because a key handed to a third party leaks comparatively easily. Layer user authentication and permission checks on top.

Why must an API key not go in the URL?

Because the content of a URL stays in web server logs. OWASP says not to put sensitive information in URLs and treats a form like ?apiKey= as a bad example. For retrieval requests, sending it in an HTTP header is given as the method.

Next step

Failures in API authentication are in API authentication flaws, and a case of a leaked key with the response is in access key leaks. The free URL check shows only what is visible from outside, and for a review of how keys are handled, contact us.

Frequently asked questions

Can an API key alone protect an API?

It is not enough. OWASP says not to rely on API keys alone to protect sensitive information or important resources, because a key handed to a third party leaks comparatively easily. Layer user authentication and permission checks on top.

Why must an API key not go in the URL?

Because the content of a URL stays in web server logs. OWASP says not to put sensitive information in URLs and treats a form like ?apiKey= as a bad example. For retrieval requests, sending it in an HTTP header is given as the method.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.