docs: 補齊 JSDoc 與指令檔註解、測試移至 app/test 並重建 README #10
+5
-3
@@ -16,12 +16,14 @@ export const EXCLUSIONS_PATH = '.gitea/ai-review/exclusions.json';
|
|||||||
* 建立一個停用 TLS 憑證驗證(`rejectUnauthorized: false`)的 HTTPS Agent,
|
* 建立一個停用 TLS 憑證驗證(`rejectUnauthorized: false`)的 HTTPS Agent,
|
||||||
* 供連接使用自簽或無效憑證的 OpenCode 服務時使用。
|
* 供連接使用自簽或無效憑證的 OpenCode 服務時使用。
|
||||||
*
|
*
|
||||||
* @remarks 每次呼叫都會回傳全新的 Agent 實例(不快取),建議呼叫端重用以共用連線池。
|
* @remarks 首次呼叫時建立,之後快取為模組層級單例(singleton)重複使用,
|
||||||
|
* 避免每次都新建 Agent 與連線池、浪費 TCP 三次握手。
|
||||||
|
Ghost marked this conversation as resolved
Outdated
|
|||||||
* 停用憑證驗證有中間人攻擊風險,僅限受信任的內部環境使用。
|
* 停用憑證驗證有中間人攻擊風險,僅限受信任的內部環境使用。
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Rogue
**問題**:每次呼叫都 new https.Agent(),這會建立全新的 TCP 連線池,不僅增加記憶體碎片,還浪費三次握手建立連線的時間,根本沒發揮連線池的優勢。
**建議**:將 Agent 實例化為模組層級的靜態變數(Singleton),只在第一次呼叫時建立,後續重複使用。
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Rogue
**問題**:每次呼叫都 new https.Agent(),這會建立全新的 TCP 連線池,不僅增加記憶體碎片,還浪費三次握手建立連線的時間,根本沒發揮連線池的優勢。
**建議**:將 Agent 實例化為模組層級的靜態變數(Singleton),只在第一次呼叫時建立,後續重複使用。
|
|||||||
* @returns {import('https').Agent} 已關閉憑證驗證的 HTTPS Agent 實例。
|
* @returns {import('https').Agent} 已關閉憑證驗證的 HTTPS Agent 單例。
|
||||||
*/
|
*/
|
||||||
|
let _openCodeHttpsAgent = null;
|
||||||
export function getOpenCodeHttpsAgent() {
|
export function getOpenCodeHttpsAgent() {
|
||||||
return new https.Agent({ rejectUnauthorized: false });
|
return (_openCodeHttpsAgent ??= new https.Agent({ rejectUnauthorized: false }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+7
-1
@@ -107,14 +107,20 @@ function cleanText(value) {
|
|||||||
* @param {*} value - 任意值;非字串會先經 cleanText 轉為空字串。
|
* @param {*} value - 任意值;非字串會先經 cleanText 轉為空字串。
|
||||||
* @returns {string} 正規化後、以單一空白分隔的字串(可能為空字串)。
|
* @returns {string} 正規化後、以單一空白分隔的字串(可能為空字串)。
|
||||||
* @remarks 用於 finding 與排除條目文字的雙向「包含」比對(applyExclusions、appendExclusions)。
|
* @remarks 用於 finding 與排除條目文字的雙向「包含」比對(applyExclusions、appendExclusions)。
|
||||||
|
* 因為比對常對同一段文字重複呼叫(findings × exclusions 笛卡爾積),
|
||||||
|
* 以模組層級 Map 對「字串輸入」做 memoization,避免重複跑 NFKC/正則替換。
|
||||||
*/
|
*/
|
||||||
|
const _normalizeTextCache = new Map();
|
||||||
export function normalizeText(value) {
|
export function normalizeText(value) {
|
||||||
return cleanText(value)
|
if (typeof value === 'string' && _normalizeTextCache.has(value)) return _normalizeTextCache.get(value);
|
||||||
|
const result = cleanText(value)
|
||||||
.normalize('NFKC')
|
.normalize('NFKC')
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/[\p{P}\p{S}\s]+/gu, ' ')
|
.replace(/[\p{P}\p{S}\s]+/gu, ' ')
|
||||||
.replace(/\s+/g, ' ')
|
.replace(/\s+/g, ' ')
|
||||||
.trim();
|
.trim();
|
||||||
|
if (typeof value === 'string') _normalizeTextCache.set(value, result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user
嚴重等級:🟡 警告
審查員:Assassin
問題:
getOpenCodeHttpsAgent函式明確回傳了rejectUnauthorized: false的 HTTPS Agent。在與 OpenCode 服務通訊時,這會完全停用憑證驗證,若傳輸過程被攔截,攻擊者可輕易偽裝成合法伺服器竊取機敏數據。建議:在生產環境下,請務必將此 Agent 設定為進行完整的憑證驗證。若因服務使用自簽憑證,應將該憑證加入容器的受信任憑證庫(CA Store)中,而非全域停用驗證。