Files
jsc-marketplace/plugins/companion/hooks/companion/persona/secrets.ts
T
rootandClaude Sonnet 5.5 ba5b50ad1d refactor: 拆分 cockpit 為可個別安裝的 statusbar 與 companion
- statusbar:輸入框上方狀態列,指令 /statusbar
- companion:小說角色陪伴,指令 /companion,自行渲染角色行
- companion 資料目錄改為 ~/.companion
- 整併 M4 檔案至 companion;M2 實作移至 hooks/companion/persona
- README 移除本機資料夾安裝,補上更新與移除指令

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 13:57:24 +08:00

22 lines
801 B
TypeScript

// 疑似金鑰:寫入互動記憶與注入內容前一律過濾
const PATTERNS: RegExp[] = [
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
/\bsk-[A-Za-z0-9_-]{16,}/g,
/\b(?:ghp|gho|ghu|ghs|ghr|glpat|xox[baprs])[-_][A-Za-z0-9_-]{10,}/g,
/\bAKIA[0-9A-Z]{16}\b/g,
/\bBearer\s+[A-Za-z0-9._~+/=-]{16,}/gi,
/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,
/\b(?:api[_-]?key|secret|token|passwd|password|pwd)\s*[:=]\s*\S{6,}/gi,
/\b[A-Za-z0-9+/_-]{32,}={0,2}(?![A-Za-z0-9])/g,
]
export const REDACTED = '[已遮蔽]'
export function redactSecrets(text: string): string {
return PATTERNS.reduce((s, re) => s.replace(re, REDACTED), text)
}
export function hasSecret(text: string): boolean {
return redactSecrets(text) !== text
}