Featured image: 5 step API management.

Application programming interfaces (APIs) make connections between systems that enable companies to conduct business. APIs are now one of the most popular ways for applications, microservices, and containers to communicate. They offer a wide range of benefits, including reliable communication and data transfer, streamlined development, easy scalability, and cost-effective re-usability. However, as APIs become more prevalent in the cloud-native landscape, they also leave applications vulnerable to many more security risks.

APIs can expose an application and its data, greatly expanding the attack surface and providing a range of new opportunities for attacks. Since APIs are used for communication and data transfer, an insecure API can expose sensitive customer or corporate data, causing revenue loss and damage to a brand's reputation.

Several of the most notorious breaches in recent years have been the result of API vulnerabilities, including the well-known Facebook breach in 2018 that exposed the personal data of 50 million users and cost the company millions of dollars. Furthermore, Gartner predicts that in 2022, API attacks will become the most-frequent attack vector causing data breaches for enterprise web applications.

10 essentials to mitigate API security risks

Managing the security of APIs is an increasingly vital consideration for all developers, from the start of the development process and throughout the API life cycle. In this article, we will examine ten essential solutions and tools to mitigate security risks throughout each step of the API life cycle.

1. Defining APIs

When you start building an API, the first step is to define the API and outline its specifications. If there is an error in the API specifications, this may introduce a built-in security risk that will persist through the API’s life cycle. Using a standard, such as the OpenAPI specification, helps you define the API properly and ensure API security from the start.

You can test the machine-readable specification — using an automated API testing tool — to detect flaws and other security issues even before the API is implemented. Finding and fixing these vulnerabilities before going into production can save valuable time and expense later on by avoiding costly security disasters.

In addition, the OpenAPI spec allows you to document the security features of the API, such as the type of authentication.

Red Hat’s API Designer uses a form-based approach to design an API that automatically complies with OpenAPI specifications and will aid you in saving effort and time API specifications are typically written in YAML or JSON, but with Red Hat API Designer, prior knowledge of YAML or JSON in order to design an API is not needed.

2. API mocking and testing

Once API specifications are defined using a tool like Red Hat API Designer you can feed those specs into an API Mocking tool of your choice. This is another important step you can implement early in the life cycle to ensure API security.

API mocking tools simulate the API behavior prior to implementation and test the API flows for any vulnerabilities and edge cases that could lead to a security breach. A mocked API will help you build quick product prototypes and expose some of the security risks so they can be fixed at an early stage of development.

3. Service registry: API schema discovery

From the start of the API development process, it is also critical to ensure consistency. In a large development organization, multiple teams are typically involved in building APIs and this can lead to inconsistencies in the way APIs are designed and developed. These oversights can leave open potentially damaging security loopholes. A service registry solves these discrepancies.

Service registry serves as a single source of the truth, facilitating the consistent reuse of schemas and API designs across your organization. Rather than building the application first, and offering a contract for the API after the fact, you can use a service registry to define the contract in advance so other development teams know exactly how their applications should connect with your application. For example, when a security standard for an API is built into the design and published to the service registry, and other teams reuse the API, they will automatically implement the most current — and most secure — version of the API.

Development teams can document reusable APIs and make them available for browsing and downloading with Red Hat OpenShift Service Registry. With support for multiple API formats, Red Hat OpenShift Service Registry is delivered as a high-availability registry service that is fully hosted and managed by Red Hat. This service helps development teams publish, discover, and reuse artifacts.

4. API implementation

Security is just as necessary during API implementation due to the variety of security considerations that must be addressed. The languages, runtimes, frameworks, web servers, and other tools that you choose to build your APIs can result in security risks as well. To ensure security, you must choose languages, frameworks, and other technologies that are well-supported either by open source communities or commercial product vendors who can provide a fix for any security issues.

For example, there was a previously unknown and unsuspected security risk in the API development stack. Hackers exploited a vulnerability in Log4j, a fundamental logging tool. They gained access to valuable consumer and corporate data by querying services with malicious code. This example serves as an alarming reminder that you must consider each component of your API development stack very carefully.

Red Hat Runtimes can help you develop and manage your cloud-native apps. This toolbox provides secure, market-proven technologies and production-ready capabilities, including application runtimes, data caching, data messaging, and security. It also offers lightweight runtimes and frameworks (like Quarkus) for highly-distributed cloud architectures, such as microservices.

5. Service mesh for microservices

As your applications evolve into collections of decentralized microservices, managing security for those multiple services becomes more challenging. APIs are the primary method of communication and data transfer within Micro Services Architecture (MSA). More microservices and more APIs translate into greater numbers of attack points, which must all be addressed. Service mesh is an effective solution to this problem.

Service mesh provides a layer of management across all your microservices, delivering control and security. A service mesh is a transparent, dedicated infrastructure layer that resides outside of an application, designed to control how microservices within the application share data with each other. The service mesh enables developers to introduce added security features to microservices including service identity, traffic management, mutual TLS (mTLS), certificate management, audits, and tracing requests.

Red Hat OpenShift Service Mesh, based on the open source Istio project, provides a uniform way to manage and secure microservices-based applications and out-of-the-box security for your distributed applications including transparent mTLS encryption, and fine-grained policies that facilitate zero-trust network security.

Learn more about Red Hat’s approach to service mesh technology.

6. Security automation

Once your API is in production, security remains a top priority. Many IT organizations handle security operations manually, however, and this can be time-consuming, tedious, error-prone, and overwhelming. According to a Cisco study, 60% of security teams receive more than 5,000 alerts per day, and 16% receive more than 100,000 alerts daily. Consequently, typical security teams only review and respond to 48% of the alerts they receive and only 50% of legitimate threats are remediated. This gap leaves many applications vulnerable to attack.

The automation of the manual tasks associated with maintaining security removes human error from the equation. With automation, you make API security a built-in, unavoidable feature throughout the API life cycle. Automation ensures that critical security checks and tests are always performed automatically, in order to reveal any flaws or weaknesses that could lead to a security issue. Applying automation across your API security efforts also increases consistency, with repeatable checks and tests, so you can have the comfort of knowing that the APIs are subjected to the same level of scrutiny every time.

When every solution in a security portfolio is automated through the same language, both analysts and operators can perform a series of actions across products in a fraction of the time, maximizing the overall efficiency of the security team. In addition, a common framework and language allow security and IT teams to share designs, processes, and ideas more easily both internally and across your organization.

The benefits of security automation are clear and quantifiable — according to an IBM report, fully deploying security automation can reduce the average cost of a breach by 95%.

You can automate complex and tedious security procedures to ensure the security of your API with the Red Hat Ansible Automation Platform. Red Hat Ansible Automation Platform enables you to automate and integrate different security solutions that can investigate and respond to threats across the enterprise in a coordinated, unified way using a curated collection of modules, roles, and playbooks.

7. API gateway

When your application is in production, that is when you face the greatest threat of cyberattack. Often these threats come in the form of what appears to be a typical user. To thwart this type of attack, an API gateway serves as a security guard, allowing you to authenticate traffic and manage how APIs are being used. The API gateway acts as a secure access point to prevent hackers from accessing your backend systems.

An API gateway sits between a client and a collection of backend services and acts as a reverse proxy to accept all API calls, aggregate the various services required to fulfill them and return the appropriate result. An API gateway can also provide security features such as identification and authentication, traffic management, rate limiting, and throttling.

An API Gateway also enables you to execute security policies against the incoming API requests that play a key role in keeping your APIs secure such as IP filtering/Check, CORS handling, URL rewrite, TLS certificate validation, header modification, and JWT claim check.

One option for API Gateway technology is Red Hat 3scale API Management, which includes an API gateway to protect your APIs and acts as the major point of enforcement for API traffic.

At the API gateway, Red Hat 3scale API Management tasks include:

  1. decodes timestamped tokens that expire
  2. checks that the client identification is valid
  3. confirms the signature using a public key

8. API authentication and authorization

Another API security imperative, while in production, is to make sure every user is recognized and has permission to interact with the application. Authentication and authorization are the two primary solutions to accomplish this objective.

Authentication identifies the requester, and only allows access to the application for authenticated end-users. Methods of authentication include:

  • API Key: a single token string.
  • API ID and Key: a two-token string solution, such as username and password.
  • Oauth: an open protocol to allow secure authorization. Oauth verifies the end-user by obtaining basic profile information and using an authentication server, rather than using passwords.

Authorization is a step beyond authentication, analyzing the user profile to decide if the user or group is authorized to have access to the application or data. OpenID Connect (OIDC) is an identity layer on top of the OAuth 2.0 protocol. It allows clients to verify the identity of the end user based on the authentication performed by an authorization server and basic profile information about the end user.

Red Hat 3scale API Management supports all the aforementioned authentication patterns. Red Hat 3scale also includes Red Hat’s single sign-on technology (SSO) which enables OIDC.

9. Rate limiting

In production, over-use of an API is an indicator of a potential security breach. You must set certain controls on usage to assure APIs are not misused. The practice of “rate limiting” is a method of control that involves restricting the number of requests sent to an API, and this is a very effective way to prevent certain security problems such as distributed denial-of-service (DDoS) attacks. DDoS is an attack that uses bots to generate traffic spikes in order to disrupt a service, and rate limiting of an API can impede this type of attack because it limits how often a user can repeat a request. This is accomplished by tracking the IP addresses associated with requests, as well as time between requests and number of requests within a certain period.

Control the traffic going to an API with Red Hat 3scale API Management, which offers application plans and policies that include rate limiting.

10. API monitoring

Finally, monitoring API usage is necessary for the entire time the API is in production. API analytics can provide extensive insight into the usage, behavior, and security of your APIs. While this is important for managing API performance, monitoring APIs for sudden abnormal spikes in usage or changes in patterns can also help you identify a compromised API or an unauthorized user trying to break into your system. Another aspect of Red Hat 3scale API Management includes comprehensive API analytics to track the usage of your APIs.

How Red Hat secures APIs

There are risks at every stage of the API life cycle, therefore security must be an ongoing priority throughout the development process. Red Hat’s broad portfolio offers a wide range of capabilities to reliably secure your APIs at every phase of the process.

We described how you can accomplish the following with Red Hat solutions:

  • Design secure APIs
  • Establish policies governing security and usage
  • Deploy an API gateway to control traffic
  • Implement a service mesh with built-in security
  • Incorporate security features such as authentication and authorization
  • Monitor APIs
  • Automate security processes

Discover more about the many ways Red Hat can fortify your API security and DevSecOps initiatives.

Last updated: December 27, 2023