Skip to content

Unhandled OSError in ZoneInfoBackend.to_tzobj with crafted timezone string #155

Description

@lebaudantoine

We observed that passing certain crafted strings to zoneinfo.ZoneInfo() can raise an unhandled OSError instead of being converted into TimeZoneNotFoundError.

Current code:

def to_tzobj(self, tzstr):
    if tzstr in (None, ""):
        raise TimeZoneNotFoundError
    try:
        return zoneinfo.ZoneInfo(tzstr)
    except zoneinfo.ZoneInfoNotFoundError as err:
        raise TimeZoneNotFoundError from err

Example malicious input that triggered this:

"${(new java.io.BufferedReader(new java.io.InputStreamReader(((new java.lang.ProcessBuilder(new java.lang.String[]{"timeout","0"})).start()).getInputStream()))).readLine()}${(new java.io.BufferedReader(new java.io.InputStreamReader(((new java.lang.ProcessBuilder(new java.lang.String[]{"sleep","0"})).start()).getInputStream()))).readLine()}"

Backend context:

class ZoneInfoBackend(TimeZoneBackend):
    utc_tzobj = zoneinfo.ZoneInfo("UTC")
    all_tzstrs = zoneinfo.available_timezones()
    base_tzstrs = zoneinfo.available_timezones()

    all_tzstrs.discard("Factory")
    base_tzstrs.discard("Factory")

Question:
Should to_tzobj() first validate that tzstr exists in all_tzstrs before calling zoneinfo.ZoneInfo() to ensure consistent error handling and avoid unexpected exceptions?

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