github / github/codeql

False nagative: InsecureTemporaryFile misses source pattern `tempfile.NamedTemporaryFile(delete=False)` path exposure

オープン
#21,669 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

The current query only flags deprecated/insecure temporary file APIs like `tempfile.mktemp` and `tempfile.tmpnam`. However, a modern and equally dangerous source pattern involves `tempfile.NamedTemporaryFile(delete=False)` where the generated filename is returned or exposed elsewhere.

I encountered this [pattern ]( https://github.com/moest-np/center-randomize/blob/987c14c964556f0b6bced9238989beedafaee7aa/app.py#L112)in a real-world GitHub repository. When `delete=False` is used, the temporary file persists after the context manager exits or the file handle is closed. Returning or exposing the filename creates a race window.

```python
def save_file_to_temp(file_obj):
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
file_obj.seek(0) # Go to the start of the file
temp_file.write(file_obj.read())
return temp_file.name
```

Since this uses a standard API rather than a deprecated one, linters won't flag it, making it easy to overlook.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

InsecureTemporaryFile クエリから開始し、既存の検出で tempfile.mktemp と tempfile.tmpnam がどのようにカバーされているかを確認します。ファイル名が返されるか公開される場合の NamedTemporaryFile(delete=False) パターンに対するリグレッションカバレッジを追加し、その後クエリのテストを実行します。この issue では具体的なファイルやテストパスは指定されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
security
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。