Skip to content

Commit 89dcc5c

Browse files
gh-111783: Add a warning for reopening files by name to NamedTemporaryFile
1 parent df34a2f commit 89dcc5c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Doc/library/tempfile.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ The module defines the following user-callable items:
106106
The latter approach is recommended as it provides assistance in automatic
107107
cleaning of the temporary file upon the context manager exit.
108108

109+
.. warning::
110+
111+
Reopening the temporary file by name is only safe when the file's
112+
directory is trusted. See :cwe:`377` for more information.
113+
109114
Opening the temporary file again by its name while it is still open works as
110115
follows:
111116

@@ -409,6 +414,7 @@ Here are some examples of typical usage of the :mod:`!tempfile` module::
409414

410415
# create a temporary file using a context manager
411416
# close the file, use the name to open the file again
417+
# this is only safe if the directory cannot be modified by untrusted users
412418
>>> with tempfile.NamedTemporaryFile(delete_on_close=False) as fp:
413419
... fp.write(b'Hello world!')
414420
... fp.close()

0 commit comments

Comments
 (0)