Lucene search

K
d0znppIvan NovikovD0ZNPP:46CCAE38D30F0683913CAFBFD33495CA
HistoryOct 11, 2021 - 3:52 p.m.

API security — Wiki: What is ❓ Why ❓ For PenTest & Best Practice

2021-10-1115:52:14
Ivan Novikov
d0znpp.medium.com
34

API security — Wiki: What is ❓ Why ❓ For PenTest & Best Practice

What does api mean?

For beginners, API refers to the Application Programming Interface designed for effortless communication between two different applications. This is why it’s often referred to as the middle person for the application. While we discuss API, mentioning API security is essential, as it’s what protects the integrity of the apps, owned and used by the users.

Let’s understand the API meaning in detail. Today’s world is driven by IoT or the Internet of Things (IoT) wherein computing is integrated into day-to-day objects and operations. A real-life example of IoT implementation is using an app that can connect the phone with your refrigerator and allows you to operate from anywhere. Using that app, one can operate the refrigerator remotely, can find out what’s inside it, and even reduce the temperature.

For developers, API is a great tool to use while exchanging information between microservices and containers and fast-paced communication. Just as integration and interconnectivity are crucial for application development, API drives and enhances application designing.

API for different folks look really different

In the previous section, we provided a general overview of API to you. It’s usage is so wide and diverse that it works differently for different purposes.

Back-end developer:

  • **Framework:**A well-structured plan or strategy that defines how operations and processes will work;
  • ‍**Specification:**A Swagger-based documentation that describes the functioning of REST or OpenAPI. For example, a document explaining the technicalities of circuit version 3, a clarification on everything related to Geo PC, a GraphQL schema that is different from the default version, or protobuf.
  • Data and Business Logic: It was impossible to imagine operating without HTML markup, but not anymore. Now, we can split data, logic and markup during the development today. Back-end developers prefer separating data and logic between clients (e.g. mobile app or browser). This helps them reuse and repurpose their code or data, e.g. single page applications and mobile apps can use the same data. Similarly, business integration, especially custom integrations, can be handled due to this.
  • Unified mobile, web and integration backends to improve and simplify the synchronization process.

DevOps:

  • Specification meets Production: For example, if an endpoint returns 502 very often, shouldn’t you truy to find the reason and mitigate it? Same has to be done for other issues and needs.
  • Scaling: If an endpoint requires scaling to solve 504 Error, it is essential to find out the responsible microservice, optimal process, and orientation of the problem (e.g., REST API info GraphQL)

Security:

  • New protocols: My firewalls, scanners, and other old tools stopped working on upgrading. What to do?!
  • East-west security: The communication within my network is not monitored well?!
  • New security, networking or other IT compliance

Why is API security important?

As said previously, API and API security go hand in hand. Paying attention to the API security is crucial, as APIS with poor API security are prone to be attacked, hacked, or exposed. APIs are mainly used for exchanging information, connecting services, and transferring data, and falling into the nippers of data breaches leads to major losses for businesses.

Depending upon the vitality and significance of data/information exchanged by APIs, businesses can adopt diverse API security approaches. For instance, APIs that are used to connect to any of the third-party applications, like in the above-mentioned example, need to be accessed for their ability to funnel data back to the internet. You won’t be worried if someone figures out what’s stored in your fridge. But, if an API of the same app is tracking your location then it’s high time to fix it.

What Does API Security Entail?

APIs, related to the app that you own, can only be controlled. This is why API security is focused on securing APIs that are exposed to a user, directly or indirectly. APIs, offered by other parties, that a user consumes are not a prime priority of API security as valuable insights related to such APIs can be gained by detailed analysis of outgoing API traffic.

One another key point to note here is that API security practice implementation involves multiple teams and systems. Network security principles like throttling, rate limiting, along with key data security concepts like identity-based security and analytics are a part of API security.

API Security for REST, SOAP, GraphQL, gRPC, Websocet and Webhooks

Based on the requirements, APIs can be used in various forms and styles. The chosen API style (REST, SOAP, GraphQL, gRPC, Websocet or Webhooks) decides how API security should be applied and implemented. Before web APIs came into being, the key API style uses were SOAP Web Services. In the era of service-oriented architecture WS from 2000–2010, XML was used widely.

The SOAP

SOAP is an XML-based messaging/communication protocol and refers to Simple Object Access Protocol. It is used widely for information exchanged between computers.

This protocol can extend HTTP and offers data transport means for web services. Using this protocol, one can easily exchange all-inclusive documents or call for a remote procedure.

Though SOAP can be used in various messaging systems, its key focus is on remote procedure calls transferred via HTTP. It’s distinct from other frameworks like CORB, DCOM, and JAVA RMI in one aspect — the whole message is penned down in XML in SOAP. It makes SOAP protocol unique and language-independent.

REST

Introduced by Roy Fielding, Representational State Transfer or REST is HTTP protocol-based web standard architecture revolving around the combined and interrelated resources. All the resources, used by REST, are accessed only using HTTP standardized methods.

For each HTTP request to process, REST uses four kinds of verbs: GET, POST, PUT, and DELETE.

APIs, functioning via HTTP Requests, use RESTful architectures. For developers, it’s the easiest possible tool for comprehending the API functions and behavior. Its usage makes API architecture much more convenient to maintain and scale. It makes APIs accessible for both internal and external developers.

gRPC

gRPC is an open-source, cutting-edge, and high performing framework designed to evolve the old-school Remote Procedure Call or RPC protocol. It is majorly used to streamline the communication and messaging procedure of client and back-end services. It uses HTTP/2 for its transport protocol, which is a binary framing protocol.

gRPC is utterly lightweight and is more than 8 times quicker than JSON. To accomplish the job, gRPC calls an open-source technology, Protocol Buffers. Using its help, gRPC uses a very proficient and platform-neutral serialization format for structured messages. In API, the use of gRPC allows developers to figure out which procedure should call for and assess the parameter values.

Webhooks

Webhook is an auto-generated message sent from one to another application. In other words, it’s used for establishing communication between two software. They are used for sending/extracting real-time updates. In situations where API use will waste time and resources or there are no constant updates, it’s wise to use webhooks over API.

As webhooks contain crucial information and transfer it to the third-party servers, API security practices like performing basic HTTP authentication procedures and TLS authentication are also implemented during the use of webhooks.

WebSockets

WebSockets is a two-way communication protocol designed to offer full–fledged communication channels between the clients and the servers. Here, the communication happened at both ends at the same time. The limitations of HTTP protocol can be easily curbed by this protocol.

It starts as HTTP requests and responses that the client uses to create a WebSocket connection. Server responses to that request. After the initial communication connection is established, both the clients and the server are allowed to use the current TCP/IP connection. Data/information flows over this connection via a fundamental framed message protocol.

API Security for Cloud, On-premises and Hybrid Deployments

The current advancements in the technology areas like cloud services, integrated platforms, and API gateways have granted APIs providers the ability to secure the API in multiple ways. The type of technology stack picked for building the APIs has a direct impact on the procedure used for securing the APIs.

For instance, a large organization might be using multiple applications with their own APIs. As organizations merge all these applications, various API silos or stacks are created. The API security requirements related to one API silos can be easily directly mapped from the silo’s technology.

From a portability point of view, it’s crucial to have used security configurations to be highly portable so that they can be easily transported or extracted to any futuristic technology.

In a heterogeneous ecosystem, the API security-specific infrastructure across the API silos is used widely for defining the API security practices. The connection between API silos and API security infrastructure is configured as sidecars, sideband agents, and APIs embedded between cloud and on-premise deployments.

Layers of API Security

API security is a diverse area with multiple layers. The focus of each layer is on specific API security and is designed to earn a specific and strong protection level.

API Discovery

The first layer of API security is dedicated to API discovery, as one can’t save anything if there is no idea about the target or threat. There are a couple of obstacles that keep security operatives away from having full visibility of the used APIs. API silos, as quoted above, is the first obstacle, as it hampers the API visibility as it grants access to a partial API list.

Rogue or shadow API is the second most hurdle in API visibility. It occurs when an API that is a part of the development and itself serves as application implementation. Shadow APIs happen when an API is developed as part of an application but the API itself is considered an implementation detail of the application and is only known by a close-knit group of developers. Shadow APIs are not on the radar of security operatives because they don’t have visibility into the implementation details.

Finally, APIs go through their lifecycle. An API evolves, new versions of an API come up or an API may even be deprecated but continue to operate for a temporary period for backward compatibility and then be forgotten or gradually fall off the radar because they receive very little traffic.

API discovery is a race between API providers and hackers who will easily exploit the APIs when found. To discover your APIs before attackers do, you can mine your API traffic metadata. This data is extracted from API gateways, load balancers, or directly inline of network traffic and then fed to a specialized engine that reports on an effective list of APIs which can then be compared with catalogs of APIs that are available via an API management layer.

API Top 10 Security Threats

API1:2019Broken Object Level Authorization

APIs will in general uncover endpoints that handle object identifiers, making a wide assault surface Level Access Control issue. Item level approval checks ought to be considered in each capacity that gets to an information source utilizing a contribution from the client.

API2:2019Broken User Authentication

Validation systems are frequently executed mistakenly, permitting assailants to think twice about tokens or to take advantage of execution defects to accept other client’s characters for a brief time or for all time. Compromising a framework’s capacity to distinguish the customer/client, compromises API security generally speaking.

API3:2019Excessive Data Exposure

Anticipating nonexclusive executions, engineers will in general uncover all item properties disregarding their singular affectability, depending on customers to play out the information sifting prior to showing it to the client.

API4:2019 Lack of Resources and Rate Limiting

Frequently, APIs don’t force any limitations on the size or number of assets that can be mentioned by the customer/client. Not exclusively would this be able to affect the API worker execution, prompting Denial of Service (DoS), yet additionally leaves the entryway open to verification imperfections like animal power.

API5:2019Broken Function Level Authorization

Complex access control strategies with various chains of command, gatherings, and jobs, and a hazy detachment among authoritative and ordinary capacities, will in general prompt approval blemishes. By taking advantage of these issues, assailants access other clients’ assets as well as regulatory capacities.

API6:2019Mass Assignment

RESTricting customer gave information (e.g., JSON) to information models, without legitimate properties sifting dependent on an allowlist, for the most part prompts Mass Assignment. Either speculating objects properties, investigating different API endpoints, perusing the documentation, or giving extra article properties in demand payloads, permits assailants to change object properties they shouldn’t.

API7:2019Security Misconfiguration

Security misconfiguration is ordinarily an aftereffect of unstable default designs, fragmented or impromptu arrangements, open distributed storage, misconfigured HTTP headers, pointless HTTP techniques, lenient Cross-Origin asset sharing (CORS), and verbose mistake messages containing delicate data.

API8:2019Injection

Infusion blemishes, like SQL, NoSQL, Command Injection, and so forth, happen when untrusted information is shipped off a translator as a component of an order or question. The assailant’s noxious information can fool the translator into executing accidental orders or getting to information without appropriate approval.

API9:2019Improper Assets Management

APIs will in general uncover a larger number of endpoints than customary web applications, making appropriate and refreshed documentation exceptionally significant. Appropriate has and conveyed API forms stock additionally assume a significant part to relieve issues, for example, censured API forms and uncovered investigate endpoints.

API10:2019Insufficient Logging and Monitoring

Lacking logging and checking, combined with absent or inadequate incorporation with occurrence reaction, permits aggressors to additional assault frameworks, keep up with steadiness, turn to more frameworks to alter, remove, or annihilate information. Most break studies exhibit an opportunity to distinguish a break is more than 200 days, normally identified by outside parties instead of inward cycles or observing.

For PenTest

Trying to hack API with open source tools?

API Developers can think of using PenTest as this is the most widely used testing procedure. In the case of API PenTest, developers use Postman to proxy pre-built APIs. The pre-built API test data, created using Postman, will be swiftly used for pentesting, and reduces the testing cost while offering a detailed report.

Pentester can extract the proxy from the report and can perform multiple testing by communicating directly with the API.

How can one be double sure that the organization’s infrastructure is capable of bearing any sort of digital assault?

PenTest, when done regularly and diligently, allows developers to find out the APIs protections level and contrive remedial solutions. As PenTest is a skilled task, it’s better to hire a skilled team or simulate API threats with open source tools. For more details, have a look at this guide.

API Security Best Practices

API security is a non-negotiable aspect for data-centric projects and API development. Based upon the types of API implementation and various stages, the below-mentioned API security best practices are widely used to keep diverse security risks at bay.

  1. Use of Encryption

Encrypted APIs are hard to get attacked. APIs, used for internal and external communications, should be ciphered using the TLS encryption protocol. If possible, try to use encryption at both ends. Most TLS versions should be deployed.

  1. API Authentication

API authentication is the easiest way to ensure that APIs are not exposed to strangers. Keep track of the resources that are calling the APIs, via API key or basic access authentication. This practice will increase the difficulty of the system and make it more secure.

  1. Make Most Of OAuth&OpenID Connect

OAuth is a mechanism designed to prevent the need of remembering copious passwords. OAuth&OpenID Connect allows APIs to take the full responsibility of authorization and/or authentication.

Rather than generating different website-based accounts, OAuth allows you to connect via different credentials like Facebook or Google. In the case of APIs, it has the same sort of modus-operandi. API providers need to bank upon other third-party servers for API authorizations as API consumers, instead of offering their credentials, hand over the third-party granted token,

In this process of authorization, both the API consumers and API providers are not directly bearing the API authorization responsibility. Being a widely used delegation protocol, OAuth allows API providers to secret APIs a little further by adding the identity layer. That additional identity layer is known as the Open ID Connect standard that extends OAuth 2.0 with ID tokens.

  1. Security Experts

With multiple API security practices, it’s natural to get confused and pick one. Hiring seasoned security experts that can guide you on using suitable Antivirus systems or ICAP servers will help you big time to enjoy robust API security.

  1. Continual Monitoring, Auditing, and Logging

Prevention is better than cure. On the same note, it’s wise to keep track of the API interaction and spot the errors in the infancy stage. Audit and log relevant information on the server. These logs and records will be used later at the time of debugging. To keep track of API consumption, monitoring the dashboard is vital. When you’re updating the versions, don’t forget to add them to all the APIs.

  1. Share Limited Information

The less information you share via APIs, the fewer would be API security risks. Try to display the least possible information in the error messages.

The content and email subjects of pre-defined messages that are not customized should be locked up as IP addresses can give away the location details.

Using IP Whitelist and IP Blacklist is a great way to keep the resource access limited. API resource access should be granted only to authorized professionals and all the crucial information, saved on interfaces, should be kept hidden.

  1. Throttling and Quotas For Protection

To make sure the backend system bandwidth is as per the server’s capability, throttle yourself and grant access to only a limited number of messages. Throttling and quotas are useful to keep the dangers like DDOS at bay.

  1. Valid Data

Everything that the server is going to accept should be checked twice and validated. Any added content, data that is huge, and information shared by the consumer should be verified. JSON and XML validation are the two most widely used tools to find out whether or not the parameters are safe. They also keep SQL injection or XML bomb incidents under control.

  1. Robust Infrastructure

Implementation of updated security networks and latest server and load balance software always keep API security tight and makes APIs strong enough to deal with data breaches.

  1. Pay Attention To OWASP Top 10

In this list, the worst API vulnerabilities and their impacts are explained in detail. Experts suggest referring to this list and getting educated on the dangers that your API might encounter in the future. Alongside, securing all the OWASP vulnerabilities is also crucial

  1. Use API Firewalls

Just as building a wall around our home keeps unwanted access controlled, building API firewalls ensures APIs have only allowed access. While you’re firewalling the APIs, make sure two layers are added.

The first layer should be used to perform basic security checks like paying attention to the message size, the presence of SQL injections, and blocking the intruders instantly.

The second layer should be in LAN loaded with high-end security mechanisms.

  1. API Gateway Deployment

APIs that are well managed are less prone to dangers. For effortless API management, we suggest using API Gateways as they allow you to control, monitor, and secure the API traffic from beginning to end.

How to secure API and cloud-native apps

Use Wallarm — a dependable and complete API security tool — designed to safeguard websites, microservices, and APIs from all sorts of dangers including OWASP Top 10, bots, and application abuse easily.

The great part is Wallarm’s zero manual rule configuration and ultra-low false positives with Wallarm. Only reliable and real-time API security analysis and viable solutions will be offered. There is a free trial and demo offered for the convenience of the users. The tool is capable of protecting APIs of all sorts such as REST, SOAP, graphQL, gRPC.

Our seasoned API security team is skilled enough to secure APIs in any sort of environment. We have mastered the art and science of API security in AWS, GCP, Azure and IBM Cloud ecosystem, regardless of the type of deployment.

Originally published at https://www.wallarm.com.