Skip to content

Commit

Permalink
script: Change insecure mktemp to NamedTemporaryFile (#3444)
Browse files Browse the repository at this point in the history
Deprecated mktemp function returns an arbitrary file name to use for a temporary file. However, the application does not immediately create/open this file.

This introduces an opportunity for an attacker to interfere with the file to be created. Documentation on tempfile recommends replacing mktemp with NamedTemporaryFile. By doing this, there is no window between getting the temp file name and opening it.
  • Loading branch information
Ntp9413 committed Feb 22, 2024
1 parent e0f9153 commit f3172de
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/grass/script/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@

def write_gisrc(dbase, location, mapset):
"""Write the ``gisrc`` file and return its path."""
gisrc = tmpfile.mktemp()
with open(gisrc, "w") as rc:
with tmpfile.NamedTemporaryFile(mode="w", delete=False) as rc:
gisrc = rc.name
rc.write("GISDBASE: %s\n" % dbase)
rc.write("LOCATION_NAME: %s\n" % location)
rc.write("MAPSET: %s\n" % mapset)
Expand Down

0 comments on commit f3172de

Please sign in to comment.