Skip to content

[Bug] 500 error when request header has 'x-forwarded-port' which is not an integer #1768

@jgabaud

Description

@jgabaud

Expected Behavior

Proper error or header ignored when request header 'x-forwarded-port' is not an integer (string for example).

Actual Behavior

500 error

Steps to Reproduce

  1. Use await AsgiMiddleware(app).handle_async(req, context)
  2. Make a request with headers['x-forwarded-port']="xxx"
  3. ValueError: invalid literal for int() with base 10: 'xxx' => 500 error

Relevant code being tried

Relevant log output

Traceback (most recent call last):
  File "/home/site/wwwroot/function_app.py", line 228, in http_trigger
    return await AsgiMiddleware(fastapi_app).handle_async(req, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure/functions/_http_asgi.py", line 209, in handle_async
    return await self._handle_async(req, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure/functions/_http_asgi.py", line 212, in _handle_async
    asgi_request = AsgiRequest(req, context)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure/functions/_http_asgi.py", line 28, in __init__
    super().__init__(func_req, func_ctx)
  File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure/functions/_http_wsgi.py", line 44, in __init__
    self.server_port = str(self._get_port(url, self._lowercased_headers))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure/functions/_http_wsgi.py", line 116, in _get_port
    return int(lowercased_headers['x-forwarded-port'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '90344081.test.com'

requirements.txt file

Where are you facing this problem?

Local - Core Tools

Function app name

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions