Python: Add query for unsafe use of tempfile.mktemp.#785
Python: Add query for unsafe use of tempfile.mktemp.#785markshannon merged 12 commits intogithub:masterfrom
tempfile.mktemp.#785Conversation
felicitymay
left a comment
There was a problem hiding this comment.
Thanks for pinging me. I've made a few text suggestions, but nothing major.
| @@ -0,0 +1,20 @@ | |||
| /** | |||
| * @name Insecure temporary file | |||
| * @description Creating a temporary file using mktemp may be insecure. | |||
There was a problem hiding this comment.
The convention is to put code elements in single quotes in the description, so mktemp -> 'mktemp'.
There was a problem hiding this comment.
I've rewritten the description, since the query now supports two other insecure functions (but perhaps it's too vague now?). Please let me know if you think it needs further changes.
| <code>mktemp</code> returns. Opening a file with this name must then happen | ||
| separately, and there is no guarantee that these operations will happen | ||
| atomically. Because of this, it may be possible for an attacker to interfere | ||
| with the file before it is opened. |
There was a problem hiding this comment.
Suggest revising along the following lines to reduce sentence length and, I hope, improve clarity:
Using the
mktempfunction in thetempfilemodule to create a file is insecure because the function doesn't ensure exclusive access to the file. It returns afilenamethat is guaranteed to be unique on creation but the file must be opened in a separate operation. There is no guarantee that the creation and open operations will happen atomically. This provides an opportunity for an attacker to interfere with the file before it is opened.
There was a problem hiding this comment.
I have rewritten this based on your suggestions.
python/ql/test/query-tests/Security/CWE-377/InsecureTemporaryFile.expected
Outdated
Show resolved
Hide resolved
| /** | ||
| * @name Insecure temporary file | ||
| * @description Creating a temporary file using mktemp may be insecure. | ||
| * @description Creating a temporary file name may be insecure. |
There was a problem hiding this comment.
Presumably there are some ways to create a temporary file securely, so perhaps: "Creating a temporary file using this method may be insecure."?
markshannon
left a comment
There was a problem hiding this comment.
Code and tests look fine now.
Title says it all.
@felicity-semmle for the change note and
qhelp.