fix(calculate-version): 修復 AI 審查的安全與健全性問題
- Dockerfile 移除 --no-check-certificate,恢復 TLS 憑證檢查以防中間人攻擊 - config 對 GITEA_SERVER_URL 加入 http/https URL 格式驗證 - logger.fail 改為 logger.error(僅輸出不終止行程),退出移至 index 頂層處理 - index.main 改用相依注入並於頂層攔截錯誤後 exit 1,避免 library 內呼叫 process.exit - releases 將 response.text() 包入 try-catch 並附帶頁碼 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
f71d2cc35c
commit
fdf33b41d8
+17
-3
@@ -42,18 +42,32 @@ function normalizeBetaFlag(value) {
|
||||
return value === 'true';
|
||||
}
|
||||
|
||||
// 驗證字串為合法的 http/https URL,否則拋出錯誤(避免指向非預期協定或格式錯誤的位址)
|
||||
function assertHttpUrl(name, value) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(value);
|
||||
} catch {
|
||||
throw new Error(`${name} 格式錯誤,必須為合法的 URL`);
|
||||
}
|
||||
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
||||
throw new Error(`${name} 必須使用 http 或 https 協定`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 從環境變數載入並驗證執行所需的設定。
|
||||
*
|
||||
* GITEA_SERVER_URL 與 GITEA_REPOSITORY 為必填,未設定時會拋出錯誤;
|
||||
* GITEA_TOKEN 為非必填,未設定時為 null;IS_BETA 會被正規化為布林值。
|
||||
* GITEA_SERVER_URL 與 GITEA_REPOSITORY 為必填,未設定時會拋出錯誤;GITEA_SERVER_URL
|
||||
* 另需為合法的 http/https URL;GITEA_TOKEN 為非必填,未設定時為 null;IS_BETA 會被正規化為布林值。
|
||||
*
|
||||
* @param {Object} [env=process.env] - 環境變數來源物件,預設為 process.env。
|
||||
* @returns {{ serverUrl: string, repository: string, token: (string|null), isBeta: boolean }} 已驗證的設定物件。
|
||||
* @throws {Error} 當 GITEA_SERVER_URL 或 GITEA_REPOSITORY 未設定時拋出。
|
||||
* @throws {Error} 當 GITEA_SERVER_URL 或 GITEA_REPOSITORY 未設定,或 GITEA_SERVER_URL 非合法 http/https URL 時拋出。
|
||||
*/
|
||||
function loadConfig(env = process.env) {
|
||||
const serverUrl = requireEnv('GITEA_SERVER_URL', env.GITEA_SERVER_URL);
|
||||
assertHttpUrl('GITEA_SERVER_URL', serverUrl);
|
||||
const repository = requireEnv('GITEA_REPOSITORY', env.GITEA_REPOSITORY);
|
||||
const token = isUnset(env.GITEA_TOKEN) ? null : env.GITEA_TOKEN;
|
||||
const isBeta = normalizeBetaFlag(env.IS_BETA);
|
||||
|
||||
Reference in New Issue
Block a user