This vulnerability in the OpenTelemetry JS Prometheus exporter allows a remote, unauthenticated attacker to crash the Node.js process, resulting in a denial of service. The root cause is an uncaught TypeError that occurs when the built-in HTTP server attempts to parse a malformed URL.
The vulnerability lies in the _requestHandler method of the PrometheusExporter class, located in packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts. The code calls new URL(request.url, this._baseUrl) to parse the incoming request URL. However, it does not handle cases where request.url is a malformed or invalid URL, such as "http://". In such cases, the URL constructor throws a TypeError. Because there is no try...catch block to handle this exception, it propagates up the call stack, leading to an uncaught exception that crashes the entire Node.js process.
The fix for this vulnerability involves wrapping the URL parsing logic in a try...catch block. If a TypeError is caught, the server now returns an HTTP 400 "Bad Request" response to the client instead of crashing. This ensures that malformed requests are handled gracefully without impacting the availability of the application.
An attacker can trigger this vulnerability by sending a single, specially crafted HTTP request to the Prometheus metrics endpoint (defaulting to port 9464). For example, a request with the URL http:// is sufficient to cause the crash. Since the metrics endpoint is often exposed to the network for scraping by a Prometheus server, any application using the affected versions of the OpenTelemetry JS Prometheus exporter is at risk.