github / github/codeql

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

未关闭
#21,669 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
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.

贡献指南

打开贡献指南

调研方向

Start at the InsecureTemporaryFile query and inspect how existing detections cover tempfile.mktemp and tempfile.tmpnam. Add regression coverage for the NamedTemporaryFile(delete=False) pattern when its filename is returned or exposed, then run the query's tests; the issue does not name specific files or test paths.

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
security
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。