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

オープン
#21,669 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

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

調査の方向性

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

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

説明

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 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.

  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.

主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 11時間
マージ済み PR(30日)
129

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/codeql のほかの issue

github/codeql の issue をすべて見る

似ている issue

Security の issue をもっと見る

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

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