What is API?
API stands for Application Programming Interface. In simple terms, APIs enable different software components to talk to each other via a set of defined protocols and definitions.
Example: The Weather App on your phone talks to the weather forecast data center that has all the data via APIs and represents the data.
You might be familiar with IoT (Internet of Things) where every device has a computing capability.
You might be owning smart lights as well as an Air Conditioner. You also use a Smartphone with a weather app installed on the same. So, you are leaving for home, and you know it is too hot outside, you use the application of the Air Conditioner to turn it on from our Mobile – That is API.
As it is late evening, you would like to turn on the lights before reaching home, you use the app to do the same – That is API.
You’re part of a DevOps team that builds and deploys legacy and cloud-native apps in a fast-paced, iterative manner, using microservices and containers. APIs, like systems and apps, are one of the most frequent ways for microservices and containers to connect. APIs are becoming more crucial as integration and interconnectedness grow more important.
What is API Security and Why is It Important?
API security refers to the safeguarding of APIs, both those you own and those you use. API security is critical because APIs are used by organizations to link services and move data, and a compromised API can result in a data breach. They share private information about people’s finances, medical conditions, and personal lives without their consent. With that being said, not all data is the same and of equal importance, and it should not be protected in the same way. The way you secure your API will depend on the data being transferred and the sensitivity of the data.
OWASP Top 10 API Security Risks
OWASP published a list of Top 10 API Security Risks in 2019 as mentioned below:
1. Broken Object Level Authorization
APIs frequently expose endpoints that deal with object IDs, resulting in a large attack surface and difficulty with Level Access Control. Every function that accesses a data source via a user input should consider object-level authorization checks.
2. Broken User Authentication
Authentication protocols are frequently built poorly, allowing attackers to steal authentication tokens or exploit implementation vulnerabilities to assume the identities of other users temporarily or permanently. API security is compromised when the system’s ability to identify the client/user is compromised.
3. Excessive Data Exposure
In preparation for generic implementations, developers often expose all object properties without regard for their particular sensitivity, depending on clients to filter data before showing it to the user.
4. Lack of Resources & Rate Limiting
APIs frequently do not impose any limits on the size or number of resources that a client/user can request. This not only has the potential to degrade API server speed, resulting in a Denial of Service (DoS), but it also opens the door to authentication issues like brute force.
5. Broken Function Level Authorization
Authorization errors are common in complex access control policies with different hierarchies, groups, and responsibilities, as well as an unclear demarcation between administrative and routine functions. Attackers get access to other users’ resources and/or administrative functions by exploiting these flaws.
6. Mass Assignment
Mass Assignment is mainly caused by binding client-provided data (e.g., JSON) to data models without sufficient properties filtering based on a whitelist. Attackers can edit object properties they aren’t allowed to via guessing object properties, investigating other API endpoints, reading the documentation, or giving new object properties in request payloads.
7. Security Misconfiguration
Unsecure default configurations, incomplete or ad-hoc configurations, open cloud storage, misconfigured HTTP headers, unnecessary HTTP methods, permissive Cross-Origin resource sharing (CORS), and verbose error messages containing sensitive information are all common causes of security misconfiguration.
When untrusted data is provided to an interpreter as part of a command or query, injection problems such as SQL, NoSQL, Command Injection, and others arise. The attacker’s bad data can lead to the interpreter issuing unwanted commands or gaining access to data without permission.
9. Improper Assets Management
Because APIs typically expose more endpoints than standard web apps, good and up-to-date documentation is critical. Deprecated API versions and exposed debug endpoints can be mitigated by having the right hosts and an inventory of deployed API versions.
10. Insufficient Logging & Monitoring
Inadequate logging and monitoring, along with missing or ineffective incident response integration, allows attackers to continue attacking systems, maintain persistence, pivot to new systems, and tamper with, extract, or delete data. Most breach studies show that it takes over 200 days to notice a breach, which is usually found by third parties rather than internal processes or monitoring.
API Security Best Practices:
Identify the vulnerabilities
- Understanding which elements of the API lifecycle are unsafe is the only way to adequately secure an API. This can be difficult, particularly if your company uses a big number of APIs. It’s critical to think about the full API lifecycle—the API should be viewed as a software artifact that travels through all the stages of a software product’s development, testing, staging, and production.
Leverage Token-Based Authentication Framework like OAuth
- Establish trustworthy identities, and then use tokens issued to those identities to control access to services and resources.
Encrypt the Data
- All data maintained by an API must be encrypted, particularly personally identifiable information (PII) and other sensitive data protected by compliance standards and legislation. Implement encryption at rest and in transit using Transport Layer Security to ensure that attackers who gain access to your API server are unable to exploit it (TLS). To ensure that only authorized users can decrypt and modify data provided by your API, need signatures.
Use Rate Limiting
- APIs are becoming more valuable to attackers as they become more prevalent. Denial of service (DoS) attacks are now a common target for APIs. To avoid DoS attacks and safeguard against peak traffic, set rate restrictions on the manner and frequency of API calls. By restricting user connections, rate limiting can also balance access and availability.
Implement Zero Trust Methodology
- Traditionally, networks had a perimeter, with elements “within” being trusted and those “outside” being distrusted. Insider threats are growing more frequent, and legitimate users are increasingly connecting from outside the network perimeter. This is especially true for public APIs that provide access to internal software components and sensitive data to users from all around the world. The focus of security in a zero-trust environment switches from geography to specific users, assets, and resources. It can assist you in ensuring that APIs always authenticate users and applications (whether inside or outside the perimeter), grant them the least amount of privileges necessary to perform their responsibilities and keep a careful eye on abnormal activity.