This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: zoneinfo.ZoneInfo does not check for Windows device names
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: apple502j, belopolsky, eryksun, p-ganssle, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-08-04 14:36 by apple502j, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg398900 - (view) Author: (apple502j) Date: 2021-08-04 14:36
Note: this issue was submitted to security@ due to its potential as a DoS vector on 2021-05-08, but I have not received a response (excluding the automated email). It is over 88 days since the report, so I am now reporting this publicly.

Issue: zoneinfo.ZoneInfo does not check for Windows device names on Windows. For example, a timezone "NUL" do not raise ZoneInfoNotFoundError; instead, it raises ValueError ("Invalid TZif file: magic not found").

If the timezone passed is "CON", then the program would read the content from stdin, and parse it as tzdata file.

This can be abused for a DoS attack for programs that call ZoneInfo with untrusted timezone; for example, since reading CON is a blocking operation in the asyncio world, a web server that calls ZoneInfo with untrusted timezone input would stop its job and no future connections will succeed.

Note that this bug only occurs on Windows for obvious reasons.

Repro case:
>>> from zoneinfo import ZoneInfo
>>> ZoneInfo("CON")

This is related to bpo-41530 where timezone __init__.py does not raise ZoneInfoNotFoundError.

And finally, this happens with other file-based operations (and they are probably intentional); however, zoneinfo is designed to be secure by default, for example by disallowing path traversals. The interactions with Windows device names are not documented at all in the references. It's a common practice to let the users choose their preferred timezone in web applications, and such programs are expected to call ZoneInfo constructor with externally provided string. Timezone calculation should never cause a web server to stop to read stdin.
msg398918 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2021-08-04 17:45
Sorry you didn't receive a response to your security@ email, I guess my response just went to the PSRT, not to you as well. I believe we determined that this was an issue in importlib.resources generally, not specific to zoneinfo.

I think `importlib.resources.open_binary` should check if a resource is a file with `os.isfile` before opening it. That will solve the issue in zoneinfo and other similar situations.
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 88992
2021-08-04 18:03:38eryksunsetmessages: - msg398916
2021-08-04 17:45:15p-gansslesetmessages: + msg398918
2021-08-04 17:32:45eryksunsetnosy: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg398916
components: + Windows
2021-08-04 17:19:52xtreaksetnosy: + belopolsky, p-ganssle
2021-08-04 14:36:58apple502jcreate