Skip to content

[litestar] AnnotedValue partition error #4882

@0asys

Description

@0asys

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.39.0

Steps to Reproduce

  1. Enable litestar sentry sdk integration
  2. Throw error and is catched by the sentry sdk
  3. JWT authentication breaks

Error in JWT autentication, after an exception thrown and catched by the litestar sentry sdk integration:

Traceback (most recent call last):
  File "litestar/middleware/_internal/exceptions/middleware.py", line 158, in __call__
    await self.app(scope, receive, capture_response_started)
  File "litestar/_asgi/asgi_router.py", line 100, in __call__
    await asgi_app(scope, receive, send)
  File "litestar/middleware/authentication.py", line 87, in __call__
    auth_result = await self.authenticate_request(ASGIConnection(scope))
  File "litestar/security/jwt/middleware.py", line 267, in authenticate_request
    encoded_token = auth_header.partition(" ")[-1]
AttributeError: 'AnnotatedValue' object has no attribute 'partition'

I suspect the sentry sdk replaces some values AnnotatedValue and this leads to an error in the JWT auth of the litestar framework here:

https://github.com/litestar-org/litestar/blob/a733629e86a302a957d8ebb58df30ba4cf3ecf3d/litestar/security/jwt/middleware.py#L268

        auth_header = connection.headers.get(self.auth_header) or connection.cookies.get(self.auth_cookie_key)
        if not auth_header:
            raise NotAuthorizedException("No JWT token found in request header or cookies")
        encoded_token = auth_header.partition(" ")[-1]
        return await self.authenticate_token(encoded_token=encoded_token, connection=connection)

The litestar framework suggests this is a bug that has to be fixed in sentry sdk:
litestar-org/litestar#3853

Expected Result

Sentry SDK integration does not break JWT authentication middleware.
No exception for an AnnotatedValue is thrown.

Actual Result

Sentry SDK for litestar breaks the JWT authentication middleware.

Metadata

Metadata

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions