Skip to content

opentelemetry_cowboy crashes and detaches on malformed HTTP/2 :scheme pseudo-header #567

@velimir

Description

@velimir

Description

The opentelemetry_cowboy telemetry handler crashes when processing an HTTP/2 request with a malformed :scheme pseudo-header. Once the handler crashes, the Erlang telemetry library permanently detaches it, causing all subsequent requests on that node to lose OpenTelemetry tracing.

Root Cause

In opentelemetry_cowboy.erl:239, the extract_scheme/2 function only handles <<"http">> and <<"https">>:

case ReqScheme of
    <<"http">> ->
        http;
    <<"https">> ->
        https
end;

Any other value causes a case_clause crash. Cowboy does not validate the :scheme pseudo-header and passes through arbitrary values, so malformed requests (from scanners, bots, or misconfigured proxies) can trigger this crash.

Reproduction

Minimal reproduction repository: https://github.com/velimir/scheme_crash

git clone https://github.com/velimir/scheme_crash
cd scheme_crash
mix deps.get
iex -S mix

In another terminal:

nghttp -v -n -H':scheme: http://example.com/?' http://localhost:8080/

Error Output

[error] Handler {:opentelemetry_cowboy, :otel_cowboy} has failed and has been detached. Class=:error
Reason={:case_clause, "http://example.com/?"}
Stacktrace=[
  {:opentelemetry_cowboy, :extract_scheme, 2,
   [file: '.../opentelemetry_cowboy.erl', line: 239]},
  {:opentelemetry_cowboy, :handle_event, 4,
   [file: '.../opentelemetry_cowboy.erl', line: 295]},
  ...
]

Versions

  • opentelemetry_cowboy: 1.0.0
  • cowboy: 2.14.2
  • opentelemetry: 1.7.0
  • Erlang/OTP: 27.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions