Skip to content

Probably shouldn't respond with messages of arbitrary errors #99

@yamnikov-oleg

Description

@yamnikov-oleg

Default ExceptionHandler includes str(exc) into the response to the client:

def convert_unhandled_exceptions(self, exc: Exception) -> exceptions.APIException:
"""
Any non-DRF unhandled exception is converted to an APIException which
has a 500 status code.
"""
if not isinstance(exc, exceptions.APIException):
return exceptions.APIException(detail=str(exc))
else:
return exc

exc might be an internal error not meant to be displayed to the users. Its message might contain secrets or configuration data.

As an artificial example:

class MyView(APIView):
    def post(self, request):
        # Raises InternalServiceError("connection refused: http://192.168.100.100:5000")
        interval_service.submit(request.data)
        return Response()

Will respond with the following, leaking the service's host:

{
    "type": "server_error",
    "errors": [
        {
            "code": "error",
            "detail": "connection refused: http://192.168.100.100:5000",
            "attr": null
        }
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions