python-caldav / caldav

Apache License 2.0
313 stars 91 forks source link

Infinite recursion when calendar-data is not present in the body, and the server responds with error code 500. #343

Closed bchardin closed 8 months ago

bchardin commented 8 months ago

I have a server that sometimes responds with an error 500 when the user is not authenticated. When that occurs, caldav recurses indefinitely.

https://github.com/python-caldav/caldav/blob/e60f3fa3bb903b97add0737ecb1a4ddc35c1e29c/caldav/objects.py#L203-L211

In my case, replace does nothing because there is no calendar-data in the request.

A quick solution would be to check that the current fix for issue #309 is applicable to the content of the query (but there might be a better way to do it).

if ret.status == 500 and not b"getetag" in body and b"<C:calendar-data/>" in body:
    body = body.replace(
        b"<C:calendar-data/>", b"<D:getetag/><C:calendar-data/>"
    )
    return self._query(
        body, depth, query_method, url, expected_return_value
    )
tobixen commented 8 months ago

Oh, good catch and I think this is a good proposal. Would you care massaging it into a pull-request?

bchardin commented 8 months ago

It should be done, please feel free to change the branch (or anything else) as you see fit.

tobixen commented 8 months ago

Those compatibility-tweaks are always tricky, tweaks that may help some server implementations sometimes causes new issues with other server implementations. In this case though I obviously managed to introduce a bug.