Skip to content

IndexError raised when parsing AWS X-Amzn-Trace-Id header #359

@korneliacieslik

Description

@korneliacieslik

When the AWS X-Amzn-Trace-Id header is being parsed, the code assumes the presence of at least two - separators inside the Root= field. If the header is malformed or missing expected parts, this results in:

IndexError
index 1 outside of array bounds: -1...1 (IndexError)

This occurs at:

# get the content of the x-amzn-trace-id header
# see also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html
value = env["HTTP_X_AMZN_TRACE_ID"]
value&.split("Root=")&.last&.split("-")&.fetch(1)&.to_i(16)

This exception breaks metric collection and causes a 500 response

Would it be possible for the parser to return nil (or otherwise skip parsing) when the header is not a valid AWS trace header?

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