Skip to content

Crash with wrong URL #1589

@lfrodrigues

Description

@lfrodrigues

Describe the bug:

Crash due to someone sending the wrong URL format:


ValueError: Port could not be cast to integer value as '${port}'
  File "elasticapm/contrib/django/middleware/__init__.py", line 176, in process_response
    elasticapm.set_context(
  File "elasticapm/traces.py", line 1155, in set_context
    data = data()
  File "elasticapm/contrib/django/middleware/__init__.py", line 177, in <lambda>
    lambda: self.client.get_data_from_request(request, constants.TRANSACTION), "request"
  File "elasticapm/contrib/django/client.py", line 155, in get_data_from_request
    result["url"] = get_url_dict(url)
  File "elasticapm/utils/__init__.py", line 118, in get_url_dict
    port = None if parse_result.port is None else str(parse_result.port)
  File "urllib/parse.py", line 175, in port
    raise ValueError(message) from None

To Reproduce

  1. Send ${ip}:${port} as URL (or any other not valid URL). Here's a copy of the headers that were sent from nginx to our gunicorn server.
request_headers | 
{'accept': '*/*', 
'connection': 'close', 
'host': '${ip}:${port}', 
'user-agent': 'curl/7.64.1', 
'x-forwarded-for': '152.32.255.215', 
'x-forwarded-host': 'mydomain_here', 
'x-forwarded-proto': 'https', 'x-real-ip': '152.32.255.215'}

Environment (please complete the following information)

  • OS: Linux
  • Python version: 3.10
  • Framework and version: Django/3.2.13
  • Agent version: 6.9.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions