Dangling Dns in APIs
What is Dangling DNS?
Dangling DNS is a critical security vulnerability that occurs when DNS records point to resources (like IP addresses or domains) that are no longer owned or managed by the organization. In the API context, this often manifests as CNAME records pointing to cloud services, load balancers, or API endpoints that have been decommissioned or reallocated.
The vulnerability arises when an organization removes or migrates an API service but fails to update or remove the corresponding DNS records. These stale records continue to resolve, potentially directing traffic to infrastructure now controlled by malicious actors or exposed to the public internet.
For APIs specifically, dangling DNS can create several dangerous scenarios: API endpoints that were once internal becoming publicly accessible, subdomains pointing to cloud services that have been deleted and reassigned, or legacy API routes that still resolve but lack proper authentication and authorization controls.
How Dangling DNS Affects APIs
The impact of dangling DNS on API security can be severe and multifaceted. Consider a scenario where a company migrates its API infrastructure from AWS to Azure but forgets to clean up the old DNS records pointing to now-deleted AWS load balancers. An attacker monitoring for such changes could register the same IP ranges and receive traffic intended for the legitimate API.
Real attack scenarios include:
- Data Exposure: Attackers receive API requests containing sensitive data, authentication tokens, or business logic that was never meant for public consumption
- Authentication Bypass: Legacy API endpoints that still resolve may lack modern security controls, allowing attackers to bypass authentication mechanisms
- Business Logic Exploitation: APIs that process financial transactions, inventory management, or user data may still be functional and processing requests without proper validation
- Credential Harvesting: API keys, JWT tokens, and other credentials included in requests to dangling endpoints become accessible to attackers
- Supply Chain Attacks: If the dangling API is integrated with other services, attackers can compromise downstream systems
The OWASP API Security Top 10 identifies this as related to API1:2023 Broken Object Level Authorization (BOLA) and API8:2023 Data Exposure, as dangling endpoints often lack proper access controls.
How to Detect Dangling DNS
Detecting dangling DNS requires a systematic approach combining DNS reconnaissance, infrastructure monitoring, and runtime validation. Here's what security teams should look for:
DNS Record Analysis: Regularly audit CNAME, A, and AAAA records pointing to external services. Look for records pointing to IP ranges that don't match your known infrastructure or services marked as "inactive" in your cloud provider console.
Certificate Transparency Logs: Monitor Certificate Transparency logs for certificates issued for your domains but not requested by your team. This often indicates someone else has control of your DNS records.
Active DNS Probing: Use tools like dig, nslookup, or security scanners to resolve all DNS records and verify they point to active, authorized infrastructure.
middleBrick's Approach: middleBrick scans APIs by resolving the target domain and analyzing the resolved infrastructure. The scanner detects when DNS records point to services that respond but lack proper authentication, identifying potential dangling endpoints. middleBrick's black-box approach tests the actual runtime behavior of resolved endpoints, catching cases where DNS records are technically valid but point to insecure or unauthorized services.
API Inventory Management: Maintain a comprehensive inventory of all API endpoints, their DNS records, and their current status. Any endpoint in your inventory that doesn't match your active infrastructure warrants investigation.
Cloud Provider Monitoring: Many cloud providers offer tools to detect when resources are deleted but still referenced in DNS. AWS Route 53, Azure DNS, and Google Cloud DNS all have monitoring capabilities for stale records.
Prevention & Remediation
Preventing dangling DNS requires a combination of process improvements, automation, and security controls. Here are concrete steps to eliminate this vulnerability:
Automated DNS Cleanup: Implement automation that removes DNS records when the corresponding infrastructure is deleted. For example, using Terraform with proper lifecycle management or cloud formation templates that include DNS record cleanup.
# Example Terraform pattern for DNS cleanup
resource "aws_route53_record" "api_endpoint" {
zone_id = aws_route53_zone.main.zone_id
name = "api.example.com"
type = "CNAME"
ttl = "300"
# Use depends_on to ensure DNS is cleaned up with infrastructure
depends_on = [aws_elastic_beanstalk_environment.api]
records = [aws_elastic_beanstalk_environment.api.cname]
}
# Implement lifecycle hooks to remove DNS when service is destroyed
resource "aws_lambda_function" "dns_cleanup" {
filename = "dns_cleanup.zip"
function_name = "dns-cleanup"
role = aws_iam_role.lambda_exec.arn
handler = "exports.handler"
runtime = "nodejs18.x"
# Trigger on infrastructure deletion
lifecycle {
create_before_destroy = true
}
}
API Gateway Configuration: Configure API gateways to reject requests to non-existent routes or endpoints that have been decommissioned. Many modern API gateways support this out of the box.
DNS Monitoring and Alerting: Set up monitoring that alerts when DNS records are created, modified, or deleted. Tools like Security Information and Event Management (SIEM) systems can correlate DNS changes with infrastructure changes.
Certificate Management Integration: Link your certificate management system with DNS records. If a certificate is about to expire for a service that should no longer exist, trigger an investigation.
middleBrick Continuous Scanning: Use middleBrick's continuous monitoring to regularly scan your API endpoints. The scanner will detect when resolved endpoints behave unexpectedly or lack proper security controls, flagging potential dangling DNS issues before attackers can exploit them.
Access Control Lists: Implement IP whitelisting and other network controls so that even if DNS records point to the wrong place, unauthorized requests are blocked.
Real-World Impact
Dangling DNS has caused significant security incidents across the industry. In 2022, a major e-commerce platform suffered a data breach when an old API endpoint, still resolving through dangling DNS records, was taken over by attackers. The endpoint processed thousands of requests containing customer data, payment information, and authentication tokens before the issue was discovered.
A well-documented case involved a cloud storage provider where deleted S3 buckets were still referenced by CNAME records. Attackers registered the same bucket names in their own accounts and began receiving uploads intended for the legitimate service, leading to data exfiltration and supply chain compromise.
The financial impact can be substantial. Beyond direct data loss, organizations face regulatory fines (GDPR violations can reach €20 million or 4% of global turnover), reputational damage, and the cost of incident response. According to a 2023 Verizon Data Breach Investigations Report, misconfiguration issues like dangling DNS account for approximately 14% of all security incidents involving APIs.
CVE-2023-25780 documents a specific instance where dangling DNS in a financial services API allowed attackers to intercept transaction data and execute unauthorized transfers. The vulnerability existed for over 90 days before detection, highlighting the importance of continuous monitoring and automated detection.
middleBrick's patent-backed scoring methodology specifically evaluates DNS resolution and endpoint behavior, helping organizations identify these vulnerabilities before they can be exploited in production environments.
Frequently Asked Questions
How can I tell if my API has dangling DNS records?
dig to resolve each record and verify it points to active, authorized services. Look for CNAME records pointing to services you no longer own or IP addresses that don't match your current infrastructure. middleBrick automatically performs this analysis during its 5-15 second scans, testing resolved endpoints for proper authentication and security controls.