1. Home
  2. Web App Vulnerabilities
  3. How to remediate – API Detected

How to remediate – API Detected

1. Introduction

The scan detected that some XHR requests seem to call an API. This indicates potential exposure of internal APIs and may allow attackers to access sensitive data or functionality. Systems commonly affected are web applications, especially those using JavaScript frameworks to make asynchronous calls to backend services. A successful exploit could compromise confidentiality, integrity, and availability depending on the API’s function.

2. Technical Explanation

The vulnerability arises from APIs being exposed without proper authentication or authorization controls. Attackers can potentially access these APIs directly if they are reachable from the client-side code. This often occurs when developers inadvertently leave debugging endpoints open, or fail to implement sufficient security measures for API calls made by JavaScript in a web browser. There is no known CVE associated with this general detection. An attacker could exploit this by sending malicious requests to the exposed API endpoint, potentially bypassing intended access controls.

  • Root cause: APIs are accessible from client-side code without adequate security checks.
  • Exploit mechanism: An attacker crafts a request directly to the API endpoint using tools like curl or JavaScript within a web browser. For example, an attacker could attempt to retrieve sensitive data by sending a GET request to an unprotected API URL.
  • Scope: Web applications that make XHR requests to backend APIs are affected.

3. Detection and Assessment

To confirm whether a system is vulnerable, first check the client-side code for direct API calls. Then perform a thorough network analysis of all outgoing requests.

  • Quick checks: Inspect the JavaScript source code for URLs that resemble API endpoints. Use browser developer tools to monitor network traffic during application use.
  • Scanning: WAS API Scanning can be used to identify and assess exposed APIs.
  • Logs and evidence: Examine web server logs for requests originating from client-side IP addresses accessing API routes. Look for unusual patterns or unexpected data access attempts.
curl -v https://yourdomain.com/api/sensitive_data 

4. Solution / Remediation Steps

Implement precise steps to secure the exposed APIs. Ensure all API calls require authentication and authorization, and restrict access based on user roles.

4.1 Preparation

  • Ensure you have a rollback plan in place to revert the changes if needed.
  • A change window may be required, depending on the complexity of the implementation and potential impact on users.

4.2 Implementation

  1. Step 1: Implement authentication for all API endpoints (e.g., using API keys, OAuth 2.0).
  2. Step 2: Enforce authorization checks to ensure only authorized users can access specific APIs and data.
  3. Step 3: Review client-side code to remove any hardcoded credentials or sensitive information.

4.3 Config or Code Example

Before

// Unprotected API endpoint
app.get('/api/sensitive_data', (req, res) => {
  res.json({ data: 'Sensitive information' });
});

After

// Protected API endpoint with authentication check
app.get('/api/sensitive_data', authenticateToken, (req, res) => {
  res.json({ data: 'Sensitive information' });
});
function authenticateToken(req, res, next) {
  // Authentication logic here
  next();
}

4.4 Security Practices Relevant to This Vulnerability

List only practices that directly address this vulnerability type. Use neutral wording and examples instead of fixed advice. For example: least privilege, input validation, safe defaults, secure headers, patch cadence. If a practice does not apply, do not include it.

  • Practice 1: Least privilege to limit the impact if an API is compromised.
  • Practice 2: Input validation to prevent malicious data from being processed by APIs.

4.5 Automation (Optional)

# Example Bash script to check for exposed API endpoints
#!/bin/bash
curl -s https://yourdomain.com/api/sensitive_data | grep "Sensitive information" > /dev/null 2>&1
if [ $? -eq 0 ]; then
  echo "API endpoint is potentially exposed!"
fi

5. Verification / Validation

Confirm the fix by attempting to access the API without proper authentication. Verify that access is denied and appropriate error messages are displayed.

  • Post-fix check: Attempt to access the API endpoint using curl without providing any credentials. Expected output should be an unauthorized or forbidden error message (e.g., 401 Unauthorized, 403 Forbidden).
  • Re-test: Re-run the initial detection method (inspecting client-side code and network traffic) to ensure no unprotected API calls remain.
  • Smoke test: Verify that legitimate users can still access the API with valid credentials.
  • Monitoring: Monitor web server logs for unauthorized access attempts to API endpoints.
curl -v https://yourdomain.com/api/sensitive_data 

6. Preventive Measures and Monitoring

Suggest only measures that are relevant to the vulnerability type. Use “for example” to keep advice conditional, not prescriptive.

  • Baselines: Update security baselines or policies to require authentication for all API endpoints.
  • Pipelines: Add static application security testing (SAST) tools to your CI/CD pipeline to identify potential vulnerabilities in client-side code.
  • Asset and patch process: Implement a regular review cycle for API configurations and access controls.

7. Risks, Side Effects, and Roll Back

  • Roll back: Revert the code changes made in Step 4.2, restoring the original API configuration.

8. References and Resources

  • Vendor advisory or bulletin: N/A – This is a general detection, specific vendor guidance will vary.
  • NVD or CVE entry: N/A – This is a general detection, no specific CVE exists.
  • Product or platform documentation relevant to the fix: Refer to your web application framework’s documentation for authentication and authorization best practices (e.g., Express.js documentation).
Updated on October 26, 2025

Was this article helpful?

Related Articles