Discovering and securing any API is one of the most difficult challenges for developers. The API security landscape is constantly evolving, with new threats and vulnerabilities emerging at a rapid pace. Since commercial API security solutions could be really expensive for organizations, it’s never worst to have a look at open-source alternatives. The OSS API Firewall is the pioneer in this space with more than 1 billion docker pulls after the first release in October 2021. This article will discuss its new feature: blacklisting for compromised API tokens and cookies.

1. Why do API tokens leaks happen?

When an API server is not properly secured, then it could be leaking its tokens to the internet. Bad guys could intercept traffic to the server and use the leaked tokens to authenticate themselves and access the API.

There are multiple ways this could happen, like:

  • The API is being accessed by a third-party application, either on the same or a different server.
  • The API is being accessed by another service that is directly exposed to the internet (not using TLS).
  • The API is being accessed by a service that is using an unsecured internal load balancer.

2. Are blacklists of compromised credentials and API tokens the solution?

Blacklists have been used for many years to block known bad guys from accessing specific websites or IP addresses. The general idea is to blacklist known malicious IP addresses or domains that are associated with attacks, and let through everything else. However, this approach could create other problems. To start with, a lot of companies create their own blacklists and share them with their clients in an effort to keep them safe. But this also gives every company or website that uses blacklists to track users. Blacklists are also prone to false positives, where an address or user is erroneously marked as malicious when they aren’t. In short, blacklists are only as good as the rules that create them.

3. Using OSS API firewall to prevent using leaked tokens and cookies.

If an API leak is detected, the OSS API Firewall is able to stop the affected tokens and cookies from being used. The firewall will set a policy to block all traffic from the offending API service, ensuring that the breach is contained. The firewall is able to keep the detected tokens and cookies as a blacklist. This means that all new compromised tokens and cookies will be blocked in any form of API requests to stop using them as authentication secrets.

To enable this policy, users can just put compromised tokens into the blacklist file in a plain text format. Like this:


And then apply it by the following ENV variable or CLI argument: APIFW_BLACKLIST_TOKENS_FILE

Then it’s required to set up which HTTP header or Cookie name should be used to find token value: APIFW_BLACKLIST_TOKENS_COOKIE_NAME and APIFW_BLACKLIST_TOKENS_HEADER_NAME.

If the compromised API is using JWT, it’s also possible to trim the JWT prefix by setting the variable APIFW_BLACKLIST_TOKENS_TRIM_BEARER_PREFIX to the value true or false.

Then all the requests with blacklisted tokens or cookies will be blocked by OSS API Firewall:

curl http://localhost:8080/anything -v -H "Cookie: test=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZDk5OTk5OTEifQ.NdeEQYz4vE56uJrniAHCDO2NeMJmlrUH5F_a5bQJOo4"


The OSS API firewall by Wallarm is a great option for API development. It offers a rich feature set, and its underlying technology is mature. The firewall’s new feature of blacklisting for compromised tokens and cookies is a great way to gain visibility into threats and prevent issues. The feature is easy to set up and offers a high degree of visibility into the security posture of APIs and services.