Skip to content

Commit 31ed3ef

Browse files
gh-111783: Add a warning for reopening files by name to NamedTemporaryFile (GH-150793)
1 parent 6e8fc18 commit 31ed3ef

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
@@ -107,6 +107,11 @@ The module defines the following user-callable items:
107107
The latter approach is recommended as it provides assistance in automatic
108108
cleaning of the temporary file upon the context manager exit.
109109

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

@@ -451,6 +456,7 @@ Here are some examples of typical usage of the :mod:`!tempfile` module::
451456

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

0 commit comments

Comments
 (0)