What is API Discovery, and How to Use it to Reduce Your Attack Surface
Tags: webdev, cybersecurity, devops
Published: 2024-03-07 17:28:33

APIs are the bilingual translators of the software world, enabling applications to communicate with one another seamlessly.

However, attacks targeting APIs [increased by 400%](https://www.infosecurity-magazine.com/news/api-attacks-increase-400-last-six/) at the start of 2023, and 90% of cybersecurity investigations reveal API security vulnerabilities. Although it might seem like this problem is too colossal to fix, there is a way.

What is API Discovery?

API (Application Programming Interface) discovery is the process of cataloging all internal and third-party APIs used within your organization. It helps developers find existing APIs that fulfill specific functions, avoiding redundant work and seamlessly integrating them into new applications.

APIs are crucial in software development, enabling different software applications to communicate. However, keeping track of all APIs can become challenging as your project scales. That's why API discovery is a lifesaver. There are an array of API discovery tools available, each designed to cater to different aspects of API management and security.

7 Types of API Discovery Tools
------------------------------

1.  Automated Scanners: Scan networks and applications to identify APIs.

2.  API Catalogs: Act as organized repositories maintaining up-to-date information about APIs.

3.  API Security Platforms: Focus on both discovery and security assessment. They identify vulnerabilities in APIs and provide solutions to address them.

4.  API Monitoring Tools: Track APIs' real-time activities, reveal usage patterns, and detect security breaches or performance issues.

5.  API Documentation Generators: Automate the creation of API documentation.

6.  Network Traffic Analysis Tools: Specialize in identifying API-related patterns and interactions. 

7.  Web Application Security Scanners: Target APIs within web applications to detect security vulnerabilities like SQL injection, [CSRF, and XSS](https://www.openappsec.io/post/csrf-vs-xss).

![How do APIs work](https://static.wixstatic.com/media/bc6682_9a92159e326f4c2ca308ce6821d0edab~mv2.png/v1/fill/w_925,h_325,al_c,lg_1,q_85,enc_auto/bc6682_9a92159e326f4c2ca308ce6821d0edab~mv2.png)

Security Risks of Hidden APIs
-----------------------------

As organizations increasingly rely on APIs, hidden APIs become a significant cybersecurity threat. Since they lack appropriate security measures, they are prime targets for exploitation. Here are the key risks associated with hidden APIs:

-   Unnoticed Exploitation Opportunities: Hidden APIs allow hackers to exploit them without immediate detection, providing ample time to inflict damage or steal sensitive data.

-   Ambiguous Data Transmission: The need for more transparency in shadow APIs creates uncertainty about data transmission.

-   Regulatory Compliance Challenges: Hidden APIs can lead to non-compliance with data protection laws. Organizations could face severe penalties for non-compliance in the event of a breach. 

-   Incomplete Discovery and Management: Traditional API discovery methods, which focus on internal tracking, may not reveal APIs visible to external attackers. This inside-out approach can miss APIs that are accidentally exposed or improperly secured.

-   Dynamic API Environment Challenges: Modern APIs are dynamic and constantly evolving. New APIs are frequently deployed, and existing ones are updated or retired. This constant change can make it challenging to track and secure all APIs.

What is the Difference Between Manual and Automatic API Discovery?
------------------------------------------------------------------

Understanding the characteristics of manual and automatic API discovery is key to selecting the best method for your organization.

### Manual API Discovery

Manual API discovery is a hands-on approach where team members manually track and record the APIs used within your organization. It is suitable for smaller, less complex environments but faces challenges in larger, dynamic settings.

Pros:

-   More manageable in environments with fewer APIs.

-   Offers detailed troubleshooting and direct API interaction.

Cons:

-   Requires significant human effort and dedicated personnel.

-   Often misses hidden or undocumented APIs.

-   Human mistakes can lead to inaccurate documentation.

### Automatic API Discovery

Automatic API discovery uses software tools to identify and document APIs automatically. It is best suited for large-scale, dynamic environments where managing a high volume of APIs and frequent changes is essential.

Pros:

-   Rapidly identifies APIs, saving time and effort.

-   More likely to find all APIs, including hidden ones.

-   Reduces human error.

-   Some tools offer immediate monitoring for security and performance.

-   Maintains uniform discovery methods across teams.

Cons:

-   Automated tools might incorrectly identify non-API elements as APIs.

-   Setting up automated discovery tools can be complex and time-consuming.

Why is API Discovery Important?
-------------------------------

-   Enhanced Security Insights: Provides visibility into all APIs, helping to identify weak authentication and spotting inadequate security in data handling.

-   Efficient Software Testing: Improves [API testing accuracy](https://www.jit.io/blog/api-scanner-with-owasp-zap) with access to current API versions and uncovers less obvious or undocumented APIs.

-   Improved Compliance Management: Helps maintain compliance with data protection laws by ensuring all APIs are accounted for and audited.

-   Streamlined Development: Optimizes development processes by identifying reusable APIs and helping integrate new services or systems.

-   Proactive Risk Management: Provides early detection of security weaknesses in APIs and supports strategic planning for [API security challenges](https://cybeready.com/cyber-attacks/owasp-top-10-2023).

How to Use API Discovery to Reduce Your Attack Surface
------------------------------------------------------

Let's explore six practical methods and best practices for employing API discovery to safeguard your digital assets.

### 1\. Use API Discovery Tools

![Example API](https://static.wixstatic.com/media/bc6682_b9aa40e221e24d3c9a94a6594010e665~mv2.png/v1/fill/w_925,h_459,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/bc6682_b9aa40e221e24d3c9a94a6594010e665~mv2.png)

[Automated API discovery tools](https://www.memcyco.com/home/top-api-discovery-tools-2023/) are essential in identifying both known and unknown APIs. These tools scan various segments of your network and catalog APIs, offering insights into their operations and potential vulnerabilities.

Actionable Tips:

-   Configure[ ](https://swagger.io/tools/swagger-ui/)[Swagger UI](https://swagger.io/tools/swagger-ui/) or a similar tool for automated scanning and documentation of your network's APIs. Here's a basic example of how to set up a Swagger configuration file (swagger-config.yaml) for API documentation:

swagger: '2.0'

info:

  title: Sample API

  description: API documentation for our sample API

  version: 1.0.0

host: [api.sample.com](http://api.sample.com/)

basePath: /v1

schemes:

  - https

paths:

  /users:

    get:

      summary: Gets a list of users

      responses:

        200:

          description: Successful response

-   Implement automated tools like[ ](https://cloud.google.com/apigee)[Apigee](https://cloud.google.com/apigee) or[ ](https://konghq.com/)[Kong](https://konghq.com/) to get detailed analytics and security insights for your APIs.

![Proxy Perfomance ](https://static.wixstatic.com/media/bc6682_602cbce7751a4f98ad26dfc76a681001~mv2.png/v1/fill/w_925,h_581,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/bc6682_602cbce7751a4f98ad26dfc76a681001~mv2.png)

-   Use[ ](https://www.postman.com/)[Postman](https://www.postman.com/) to manually test endpoints.

-   Use [Check Point's endpoint security solutions](https://www.checkpoint.com/solutions/endpoint-security/) for comprehensive zero-day protection.

### 2\. Explore API Marketplaces

API marketplaces provide a platform for discovering and using APIs and offer community feedback, security insights, and usage analytics. They are ideal for finding APIs vetted and reviewed by other developers and companies.

Actionable Tips:

-   Use platforms like[ Check Point API Reference](https://sc1.checkpoint.com/documents/latest/api_reference/index.html) to explore APIs that fit your automation needs. 

-   Use[ ](https://apis.guru/)[APIs.guru](http://apis.guru/)for exploring well-documented OpenAPI files. For example, imagine you are interested in integrating a weather API. By searching for "weather" on [APIs.guru](http://apis.guru/), you find several options.

![API Guru](https://static.wixstatic.com/media/bc6682_3b596869f30740fb896c67235fe25e9b~mv2.png/v1/fill/w_925,h_583,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/bc6682_3b596869f30740fb896c67235fe25e9b~mv2.png)

### 3\. Conduct Regular API Audits

API auditing systematically reviews and analyzes APIs to ensure they are secure, efficient, and compliant with relevant standards and policies. In addition, regular audits can uncover performance issues and inefficiencies in API designs and help keep API documentation up to date.

Actionable Tips:

-   Implement tools like[ ](https://portswigger.net/burp)[Burp Suite](https://portswigger.net/burp) or[ ](https://www.zaproxy.org/)[OWASP ZAP](https://www.zaproxy.org/) for in-depth security scanning of your APIs.

# Automated scan using OWASP ZAP

zap-cli start

zap-cli open-url [http://your-api-endpoint.com](http://your-api-endpoint.com/)

zap-cli active-scan --recursive [http://your-api-endpoint.com](http://your-api-endpoint.com/)

zap-cli alerts -l Informational

-   Use automated scripts to regularly test your API endpoints against common vulnerabilities like SQL injection, cross-site scripting (XSS), etc.

import requests

from bs4 import BeautifulSoup

Example of a simple script to test for XSS vulnerability

def test_xss(api_endpoint):

    payload = "<script>alert('XSS')</script>"

response = [requests.post](http://requests.post/)(api_endpoint, data=payload)

    if payload in response.text:

        print(f"Potential XSS vulnerability detected in {api_endpoint}")

test_xss("<http://your-api-endpoint.com/api/v1/login>")

-   Regularly check APIs against industry standards like RESTful API guidelines.

### 4\. Understand API Specifications

Deep knowledge of API specifications is key to understanding how APIs interact with your systems. This step involves thoroughly examining API documentation, focusing on authentication, authorization, and data handling practices.

Actionable Tips:

-   Use tools like [Check Point's AI-powered Infinity](https://www.checkpoint.com/infinity/xdr-xpr/) to prevent threats across your entire security infrastructure, including endpoints.  

-   Use[ ](https://redocly.com/)[Redoc](https://redocly.com/) to generate user-friendly API documentation.

-   Define a routine for periodically reviewing and updating API specifications. For example, you can create an automation script with[ ](https://www.npmjs.com/package/swagger-cli)[swagger-cli](https://www.npmjs.com/package/swagger-cli) like this:

#!/bin/bash

# Script to pull latest API specs and update documentation

git pull origin master

swagger-cli bundle -o ./path/to/swagger.yaml ./path/to/api-specs/

echo "API specifications updated and bundled with Swagger."

### 5\. Implement API Gateways

![API gateway](https://static.wixstatic.com/media/bc6682_f42e7c906082412a815a6b44bdc36889~mv2.png/v1/fill/w_925,h_405,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/bc6682_f42e7c906082412a815a6b44bdc36889~mv2.png)

API gateways are the entry point for managing and securing API traffic. They provide essential functions like authentication, rate limiting, request/response transformation, and collecting analytics.

Actionable Tips:

-   Configure security policies in Amazon API Gateway. For example, you can set a rate limit in the API Gateway throttling setting like the below:

{ 

"Type": "TOKEN_BUCKET", 

"rateLimit": 100, 

"burstLimit": 200 

}

-   Enable logging and monitoring in your API Gateway settings. For AWS, this can be done by integrating with CloudWatch. The below alarm configuration triggers an alert if there are more than 50 5XX errors within 5 minutes.

{

  "AlarmName": "High API Traffic",

  "MetricName": "5XXError",

  "Namespace": "AWS/ApiGateway",

  "Statistic": "Sum",

  "Period": 300,

  "EvaluationPeriods": 1,

  "Threshold": 50,

  "ComparisonOperator": "GreaterThanThreshold"

}

### 6\. Use open-appsec

![open-appsec platform](https://static.wixstatic.com/media/bc6682_5b8cbf2504a64de0ae8160e35ca57e46~mv2.png/v1/fill/w_925,h_426,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/bc6682_5b8cbf2504a64de0ae8160e35ca57e46~mv2.png)

[open-appsec](https://www.openappsec.io/)is one of the [best web application firewall (WAF)](https://www.openappsec.io/post/best-waf-solutions) and API security solutions. It stands out with its innovative ML-based engine that continuously learns and adapts to ensure your API security measures stay ahead of evolving cyber threats.

open-appsec is not limited to API security; it offers a variety of other benefits, too:

-   Prevents OWASP-10 and zero-day threats automatically with the ML engine.

-   Continuous monitoring ensures your web applications are always protected.

-   Easy [integration with Kubernetes](https://www.openappsec.io/post/why-you-need-waf-with-kubernetes), NGINX, GraphQL, HELM, and more.

-   Automatically stops and blocks malicious requests.

-   Protects against over 2,800 Web CVEs based on award-winning NSS-Certified IPS.

-   Sets a cap on how many requests can be made to APIs within a certain period.

open-appsec is an open-source project that builds on [machine learning](https://www.openappsec.io/tech)to provide pre-emptive web app & API threat protection against OWASP-Top-10 and [zero-day attacks](https://www.openappsec.io/post/zero-day-attack-prevention). It simplifies maintenance as there is no threat signature upkeep and exception handling, like common in many WAF solutions.

To learn more about how open-appsec works, see this [White Paper](https://www.openappsec.io/whitepaper)and the in-depth [Video Tutorial](https://www.openappsec.io/tutorial-open-appsec-webapp-protection). You can also experiment with deployment in the free [Playground](https://www.openappsec.io/playground).