Extract dashboard redaction helpers

Centralize dashboard secret redaction helpers and add focused regression tests.
This commit is contained in:
Eyejoker
2026-04-28 13:25:46 +09:00
committed by GitHub
parent 23c5be6ecd
commit f162f42c6b
4 changed files with 47 additions and 15 deletions

View File

@@ -2,10 +2,7 @@ import { useMemo, type ReactNode } from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
const SECRET_ASSIGNMENT_RE =
/\b([A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|API_KEY|AUTH|PRIVATE_KEY)[A-Z0-9_]*)\s*=\s*([^\s"'`]+)/gi;
const SECRET_VALUE_RE =
/\b(?:sk-[A-Za-z0-9_-]{12,}|gh[pousr]_[A-Za-z0-9_]{12,}|xox[baprs]-[A-Za-z0-9-]{12,}|eyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,})\b/g;
import { redactSecretsForMarkdown } from './redaction';
export function ParsedBody({
text,
@@ -16,9 +13,7 @@ export function ParsedBody({
}): ReactNode {
const cleaned = useMemo(() => {
if (!text) return '';
let out = text
.replace(SECRET_ASSIGNMENT_RE, (_m, key) => `${key}=***`)
.replace(SECRET_VALUE_RE, '***');
let out = redactSecretsForMarkdown(text);
if (truncate && out.length > truncate) {
out = out.slice(0, truncate) + '…';
}