Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grass.script: Change insecure mktemp to NamedTemporaryFile #3444

Merged
merged 2 commits into from
Feb 22, 2024

Conversation

Ntp9413
Copy link
Contributor

@Ntp9413 Ntp9413 commented Feb 22, 2024

Removed use of deprecated 'tempfile.mktemp' and replaced it with 'NamedTemporaryFile'.

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 temporary file name and opening it.

Following up on echoix's comment on PR #3436, This was the only instance of tempfile.mktemp I found in this project. There are other uses of a function tmp_path_factory.mktemp in various conftest files, but that is different in that it instantly creates a directory and does not pose the risk tempfile.mktemp does. Additionally tempfile.mkstemp which is occasionally used is safe as the file is automatically created with secure permissions by default.

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.
@github-actions github-actions bot added Python Related code is in Python libraries labels Feb 22, 2024
Copy link
Member

@echoix echoix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Many thanks!

@neteler neteler added this to the 8.4.0 milestone Feb 22, 2024
@echoix echoix merged commit f3172de into OSGeo:main Feb 22, 2024
25 checks passed
@echoix
Copy link
Member

echoix commented Feb 22, 2024

Again, thanks for your first contribution here! I hope to see you again, your skillset was useful for all!

@wenzeslaus wenzeslaus changed the title script: Change insecure mktemp to NamedTemporaryFile grass.script: Change insecure mktemp to NamedTemporaryFile Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libraries Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants