Skip to content

Commit 17e1da2

Browse files
Update docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-459/README.md
Co-authored-by: Bartlomiej Karas <[email protected]> Signed-off-by: dwiley258 <[email protected]>
1 parent 72b127b commit 17e1da2

File tree

1 file changed

+2
-1
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-459

1 file changed

+2
-1
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-459/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Temporary files can be used to store data, either between processes, or to prese
66

77
In Python there is two documented ways to create temporary files using the tempfile library, tempfile.mkstemp() and tempfile.NamedTemporaryFile() .
88

9-
tempfile.mksdir() creates a secure file in the most secure fashion allowing only read and write to the user who executed the python script. It returns a tuple, which does not work well with the "with" statement. This mean that the user is responsible for deleting the temporary file after use.
9+
tempfile.mkstemp() creates a secure file in the most secure fashion allowing only read and write to the user who executed the python script. The function returns a tuple containing a file descriptor and the file path, but since this tuple is not a context manager, it does not directly integrate with the "with" statement, which automatically manages resource cleanup. This means that the user is responsible for deleting the temporary file after use.
10+
1011

1112
tempfile.NamedTemporaryFile() is more advanced than the mkstemp() method as it returns a file-like object that works well with the "with" statement, although it creates the file with the same permissions as mkstemp(). The default behaviour is to delete the file once the "with" block is finished. If the file is needed outside of the with block, the delete_on_close parameter must be set to false.
1213

0 commit comments

Comments
 (0)