Summary
9Router up to version 0.4.41 exposes a Next.js API endpoint that returns plaintext API keys, token usage, and billing metadata without any authentication checks.
A remote attacker can send a single unauthenticated request to /api/usage/stats to obtain full API key strings for all connected AI provider accounts, enabling unauthorized usage, billing fraud, and quota exhaustion.
Affected context
This vulnerability occurs in 9Router deployments that expose the /api/usage/stats Next.js API route to the network, such as public SaaS instances or self-hosted installations with external access.
It manifests when the route is deployed without authentication middleware or access control, and where the response payload includes plaintext API keys, usage metrics, and cost breakdowns for connected AI provider accounts.
The issue is most severe in environments where those provider keys grant broad access to paid AI APIs or where usage-based billing is enabled.
Exploit preconditions
- Attack surface: Network-accessible Next.js API route at
/api/usage/stats - Required access: None; the endpoint is callable without authentication or prior registration
- Trigger point: A standard HTTP request (e.g., GET) to the stats endpoint
- Why exploitation is possible: Missing authentication and authorization middleware on the route, combined with returning sensitive fields (plaintext API keys and detailed usage data) directly in the response payload
Why this happens
The root cause is a lack of access control on a sensitive backend endpoint, mapping to CWE-306: Missing Authentication for Critical Function.
A Next.js API route that surfaces internal usage statistics is implemented without enforcing authentication or checking the caller's identity, effectively treating all requests as trusted.
Additionally, the endpoint returns highly sensitive secrets in clear text (API keys) alongside usage and billing metadata, aligning with CWE-522: Insufficiently Protected Credentials, where credentials are exposed without appropriate protection or compartmentalization.
Abstractly, this reflects a pattern where observability or admin-oriented APIs are built without consistent security boundaries and where secrets are embedded directly in operational telemetry.
Potential impact
- Attackers can obtain plaintext API keys for all connected AI provider accounts.
- Unauthorized use of AI APIs under the victim's billing accounts.
- Billing fraud and unexpected financial charges due to abusive or automated usage.
- Quota exhaustion, degrading or denying service to legitimate users.
- Potential downstream data exposure via abused AI provider APIs.
- Reputational damage and support burden from compromised accounts.
General mitigation guidance
Effective mitigation focuses on enforcing strong access control for sensitive operational endpoints and eliminating direct exposure of secrets in telemetry.
Recommended patterns include:
- Applying centralized authentication and authorization middleware to all API routes, especially those returning usage, billing, or administrative data.
- Designing responses so that credentials (API keys, tokens) are never included in usage or stats payloads; expose opaque identifiers or partial, non-usable references where necessary.
- Segmenting administrative and observability interfaces onto restricted networks or behind authenticated dashboards.
- Treating API keys as high-value secrets, storing them using secure secret management systems and only exposing them to components that must use them, not monitoring endpoints.
- Adopting a least-privilege principle for provider keys and using scoped credentials that minimize blast radius if misuse occurs.
- Regularly reviewing API schemas and logging configurations to ensure sensitive fields are excluded from routine responses.
How teams detect issues like this
Organizations can detect similar issues by:
- Running static or framework-aware analysis that checks for API routes without attached authentication middleware, especially under paths like
/api/admin,/api/usage, or/api/stats. - Reviewing Next.js (or equivalent) route definitions to confirm all sensitive endpoints are wrapped in access control logic, using code review checklists focused on authentication coverage.
- Implementing policy-as-code or configuration linting that flags any response schemas containing fields matching known secret patterns (e.g.,
apiKey,token,secret) in non-secure endpoints. - Monitoring logs for anonymous access to administrative or metrics endpoints and alerting on unusual access patterns.
- Using automated application security testing tools to crawl exposed routes and identify unauthenticated endpoints returning sensitive or high-value data.

