refactor(release-cleanup): 將清理邏輯由 bash 改寫為 Node.js #5
@@ -58,6 +58,12 @@ export async function cleanupReleases(client, config) {
|
||||
const toDelete = selectReleasesToDelete(releases, config.keepCount)
|
||||
|
||||
|
Ghost marked this conversation as resolved
|
||||
for (const release of toDelete) {
|
||||
// 防禦非預期結構(null/非物件),避免解構時拋出未捕捉例外。
|
||||
if (release === null || typeof release !== 'object') {
|
||||
warn('略過格式異常的成品項目')
|
||||
continue
|
||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Assassin
**問題**:雖然有 encodeURIComponent,但直接將 id 拼接至 URL 是危險操作。若 id 未經妥善驗證,攻擊者可能試圖透過特殊字元擾亂 API 路徑。
**建議**:建議確保 id 在進入此函數前,已驗證為預期的整數類型或符合嚴格格式的字串,不要完全依賴 encodeURIComponent 來防範所有注入可能。
|
||||
}
|
||||
|
||||
const { id, tag_name: tag, name } = release
|
||||
|
||||
// 要求 id 為正整數(Gitea release id 本即正整數);非整數一律略過,不僅依賴 URL 編碼防護。
|
||||
|
||||
Reference in New Issue
Block a user
嚴重等級:🟡 警告
審查員:Mage
問題:使用字串模板直接拼接 API URL:
const url =${config.releaseApiUrl}/${id};。若 API 回傳的 id 包含/或特殊字元,可能導致拼接出錯誤的 API 路徑,甚至在某些處理器上導致路徑穿越,雖是 Gitea API 但應防禦性地進行 URL 編碼。建議:建議使用 encodeURIComponent(id) 對 id 進行編碼後再拼接。