Skip to content

An href with %252F (a UID holding /) comes back under the wrong URL #835

Closed

Description

@seriouslysean

Setup: iCloud, caldav 3.5.0 and 3.6.0. The events were saved by the iOS Calendar app from invitations (a dental booking site and an Epic MyChart portal).

iCloud names an object whose UID holds a / with the slash as %2F, percent-encoded on top, so the href has %252F (the name _quote_uid() mints too, #143). A GET on the listed href works. Values scrubbed, shapes unchanged:

UID href listed
https://www.example.com/appointments/abc/?token=xyz /cal/home/https%3A%252F%252Fwww.example.com%252Fappointments%252Fabc%252F%3Ftoken%3Dxyz.ics
A7CzVJ5v/bTJo0Ebqoj2LQ==@mychart.example.org /cal/home/A7CzVJ5v%252FbTJo0Ebqoj2LQ%3D%3D%40mychart.example.org.ics

_normalize_href decodes the href, and then it gets decoded a second time:

  • In the URL Handling with Absolute URLs #435 branch: the decoded first href holds a :, so it's parsed as a URL and its path decoded again. search(), children() and sync return /cal/home/https://www.example.com/appointments/abc/. Any absolute href is decoded twice the same way.
  • In _post_multiget(), whose normalise_path() is quote(unquote(path)): multiget() returns the second object as /cal/home/A7CzVJ5v/bTJo0Ebqoj2LQ%3D%3D@mychart.example.org.ics, which doesn't exist. With url.encode-at.identity declared, requote_path() does the same in _href_to_url() and children().

I'd expect the same for any object saved by this library with a / in its UID, since _quote_uid() mints the same names (not run against the test servers). The ha-test%2Fslash plus%20uid.ics object in #826 looks like the same shape. #783 and #826 are about UID lookups; this is about the hrefs a server lists.

#836 decides absolute vs path on the raw href (RFC 4918 section 8.3) and quotes the decoded href without decoding it again.

AI usage: Claude Code imported my calendar events, debugged the failure, paired with me on the fix and wrote this report. The reproduction was run with caldav 3.5.0; Claude also saw the first case live against iCloud with 3.6.0, and the code is the same in 3.6.0 and master.

While I used AI to do a lot of the work here, this was found while solving a real problem I encountered while importing my own calendar as read-only events for an on-prem agent. This package made it much easier to accomplish that. I've put up a PR to fix it (#836), and have patched it locally to ensure it works and is well tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions