2023-07-06 17:05:53 +02:00
|
|
|
include::../common/rationale.adoc[]
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
include::../common/description.adoc[]
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
=== What is the potential impact?
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
include::../common/impact.adoc[]
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
== How to fix it
|
|
|
|
|
|
|
|
=== Code examples
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
include::../common/fix/code-rationale.adoc[]
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
==== Noncompliant code example
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
filename = tempfile.mktemp() # Noncompliant
|
|
|
|
tmp_file = open(filename, "w+")
|
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
import tempfile
|
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
tmp_file1 = tempfile.NamedTemporaryFile(delete=False)
|
|
|
|
tmp_file2 = tempfile.NamedTemporaryFile()
|
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
=== How does this work?
|
|
|
|
|
|
|
|
include::../common/fix/introduction.adoc[]
|
|
|
|
|
|
|
|
include::../common/fix/secure-api.adoc[]
|
|
|
|
|
|
|
|
Here, the example compliant code uses the more secure
|
|
|
|
`tempfile.NamedTemporaryFile` function to handle the temporary file creation.
|
|
|
|
|
|
|
|
include::../common/fix/manual-setup.adoc[]
|
|
|
|
|
|
|
|
//=== Pitfalls
|
|
|
|
|
|
|
|
//=== Going the extra mile
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Resources
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2023-07-06 17:05:53 +02:00
|
|
|
include::../common/resources/documentation.adoc[]
|
|
|
|
|
|
|
|
* https://docs.python.org/3/library/tempfile.html#deprecated-functions-and-variables[Python documentation] - tempfile
|
|
|
|
|
|
|
|
//=== Articles & blog posts
|
|
|
|
//=== Conference presentations
|
|
|
|
|
|
|
|
include::../common/resources/standards.adoc[]
|
|
|
|
|
|
|
|
//=== Benchmarks
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
'{module.method}' is insecure. Use 'tempfile.TemporaryFile' instead
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|