Dangling Dns in Adonisjs with Basic Auth
Dangling Dns in Adonisjs with Basic Auth — how this specific combination creates or exposes the vulnerability
A dangling DNS record occurs when a hostname (e.g., internal.api.example.com) still points to an IP address, but the associated service or workload has been decommissioned or moved. In AdonisJS applications that rely on Basic Auth for endpoint protection, this combination can inadvertently expose functionality or data because the application may still resolve and route requests to the stale IP. AdonisJS typically validates credentials at the route level, but if route definitions or service discovery rely on a hostname that resolves to an unintended host, the Basic Auth layer may be bypassed or misapplied, depending on how the HTTP client or proxy configuration resolves the name.
During a black-box scan, middleBrick tests unauthenticated attack surfaces and checks for authentication bypass patterns. When a dangling DNS name is reachable and responds on expected ports, middleBrick’s Authentication and BOLA/IDOR checks can detect whether endpoints are accessible without proper credentials. In AdonisJS, if Basic Auth middleware is not consistently applied or if request resolution falls back to a default or misconfigured host, an attacker may reach functionality that should be restricted. The scanner also checks Input Validation and Unsafe Consumption to ensure that hostname resolution does not lead to SSRF or exposure of internal services, which is especially relevant when Basic Auth is used as a thin wrapper over weak network boundaries.
For example, suppose an old internal service URL like http://legacy-internal.example.com is hardcoded in AdonisJS config or HTTP client helpers, and the DNS record for legacy-internal.example.com now points to a server no longer maintained. If AdonisJS routes use that hostname in proxy or HTTP request logic and Basic Auth is only enforced on the application’s own routes, an attacker may interact directly with the stale service. middleBrick’s LLM/AI Security checks do not apply here, but the scan’s Inventory Management and Property Authorization tests can surface inconsistent authorization across discovered endpoints. Remediation requires synchronizing DNS, route definitions, and authentication enforcement so that dangling names cannot bypass intended access controls.
Basic Auth-Specific Remediation in Adonisjs — concrete code fixes
To secure AdonisJS endpoints using Basic Auth and avoid issues related to dangling DNS, ensure that authentication is applied before any network calls or route resolution, and avoid relying on external hostnames for access control decisions. Use AdonisJS middleware to validate credentials on each request and ensure that any outbound HTTP requests use explicit, audited hosts rather than dynamic resolution that could follow dangling records.
Below are concrete code examples for Basic Auth in AdonisJS. The first example uses AdonisJS native middleware to enforce authentication on routes:
// start/hooks.ts
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export const authBasic = async (ctx: HttpContextContract, next: () => Promise) => {
const username = ctx.request.header('authorization')?.split(' ')[1]
const password = ctx.request.header('authorization')?.split(' ')[1]
if (!username || !password || username !== 'admin' || password !== 's3cr3t') {
ctx.response.status(401).send({ error: 'Unauthorized' })
return
}
await next()
}
// routes.ts
import Route from '@ioc:Adonis/Core/Route'
import { authBasic } from 'App/Hooks'
Route.get('/secure', authBasic, async () => {
return { message: 'Authenticated' }
})
This approach checks credentials on each request and avoids depending on external network identity. A second pattern demonstrates explicit outbound HTTP calls with fixed hosts, preventing reliance on potentially dangling DNS entries when making client requests:
import { Http } from '@poppinss/utils'
const client = new Http()
export default class ReportsService {
public async fetchReport(id: string) {
// Use a hardcoded, audited host instead of a dynamic or stale DNS name
const url = 'https://api.example.com/reports'
const response = await client
.get(url)
.auth('report-reader', 'StrongPass!2025')
.timeout({ response: 5000 })
.send()
return response.body
}
}
Additionally, audit your DNS and configuration to remove or update dangling records, and ensure that route definitions do not embed hostnames that could resolve unpredictably. middleBrick’s CLI can be used to scan your endpoints and verify that authentication is consistently enforced and that no routes inadvertently depend on unresolved or stale hostnames.