fix(TLS 驗證): 套用全域憑證忽略設定

This commit is contained in:
2026-06-26 09:20:57 +00:00
parent 4431f2fec5
commit bc0df06445
5 changed files with 21 additions and 10 deletions
+8 -4
View File
@@ -1,5 +1,7 @@
import https from 'https';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
export const GITEA_TOKEN = process.env.GITEA_TOKEN || '';
export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || '';
export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com';
@@ -14,18 +16,20 @@ export const EXCLUSIONS_PATH = '.gitea/ai-review/exclusions.json';
/**
* 建立一個停用 TLS 憑證驗證(`rejectUnauthorized: false`)的 HTTPS Agent
* 供連接使用自簽或無效憑證的 OpenCode 服務時使用。
* 供連接使用自簽或無效憑證的內部服務時使用。
*
* @remarks 首次呼叫時建立,之後快取為模組層級單例(singleton)重複使用,
* 避免每次都新建 Agent 與連線池、浪費 TCP 三次握手。
* 停用憑證驗證有中間人攻擊風險,僅限受信任的內部環境使用。
* @returns {import('https').Agent} 已關閉憑證驗證的 HTTPS Agent 單例。
*/
let _openCodeHttpsAgent = null;
export function getOpenCodeHttpsAgent() {
return (_openCodeHttpsAgent ??= new https.Agent({ rejectUnauthorized: false }));
let _insecureHttpsAgent = null;
export function getInsecureHttpsAgent() {
return (_insecureHttpsAgent ??= new https.Agent({ rejectUnauthorized: false }));
}
export const getOpenCodeHttpsAgent = getInsecureHttpsAgent;
/**
* 依環境變數解析並回傳 LLM 提供者設定。
*