Make sure temporary files are secure

This page is not yet available in Spanish. We are working on its translation.
If you have any questions or feedback about our current translation project, feel free to reach out to us!

Metadata

ID: python-security/mktemp

Language: Python

Severity: Notice

Category: Security

CWE: 377

Description

Using insecure temporary files makes your program vulnerable to attacks. The official Python documentation reports this module being vulnerable to attacks. Instead of mktemp, use the secure version mkstemp().

Learn More

Non-Compliant Code Examples

from tempfile import mktemp
mktemp(dir=self._tmp_dir)
import tempfile
tempfile.mktemp(dir=self._tmp_dir)

Compliant Code Examples

tempfile.mktemp(dir=self._tmp_dir)
import tempfile
tempfile.mkstemp(dir=self._tmp_dir)
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: esther/docs-9518-update-example-control-sensitive-log-data