function escapeHtml(text) {
return text.replace(/[&<>"]/g, (char) => {
if (char === "&")
return "&";
if (char === "<")
return "<";
if (char === ">")
return ">";
return """;
});
}
function time(at) {
return new Date(at).toLocaleTimeString("zh-CN", { hour12: false });
}
function checkRow(check) {
return `
${check.pass ? "PASS" : "FAIL"}
${escapeHtml(check.label)}
${escapeHtml(check.detail)}
`;
}
function flagRow(label, pass) {
return `
${escapeHtml(label)}
${pass ? "yes" : "no"}
`;
}
function findingRow(finding) {
return `
${finding.severity === "high" ? "高危" : "中危"}
${escapeHtml(finding.ruleId)}
${escapeHtml(finding.message)}
line ${finding.line}
${escapeHtml(finding.evidence)}
`;
}
export function mountApp(root) {
root.innerHTML = `
正在扫描 workflow…
Secret 卫生
—
secret 只能通过 env 注入到单步;不要 echo、不要在
pull_request_target 里检出 PR 代码。
`;
const score = root.querySelector('[data-testid="score"]');
const expectedPill = root.querySelector('[data-testid="expected"]');
const banner = root.querySelector('[data-testid="banner"]');
const workflowName = root.querySelector('[data-testid="workflow-name"]');
const workflowScore = root.querySelector('[data-testid="workflow-score"]');
const osesEl = root.querySelector('[data-testid="oses"]');
const flagsEl = root.querySelector('[data-testid="flags"]');
const selectedEl = root.querySelector('[data-testid="selected"]');
const findingsEl = root.querySelector('[data-testid="findings"]');
const echoCount = root.querySelector('[data-testid="echo-count"]');
const secretsEl = root.querySelector('[data-testid="secrets"]');
const checksEl = root.querySelector('[data-testid="checks"]');
const checkCount = root.querySelector('[data-testid="check-count"]');
const rulesEl = root.querySelector('[data-testid="rules"]');
const eventsEl = root.querySelector('[data-testid="events"]');
let state = null;
let selected = "good";
function current() {
return state?.workflows.find((row) => row.id === selected);
}
function renderWorkflow() {
if (!state)
return;
const workflow = current();
if (workflowName)
workflowName.textContent = workflow?.name ?? "—";
if (workflowScore) {
workflowScore.textContent = workflow
? `${workflow.score} 分 · ${workflow.high} 高 / ${workflow.medium} 中`
: "—";
}
if (osesEl) {
osesEl.innerHTML = (workflow?.flags.oses ?? [])
.map((os) => `${escapeHtml(os)}`)
.join("");
}
if (flagsEl && workflow) {
flagsEl.innerHTML = [
flagRow("xvfb", workflow.flags.xvfb),
flagRow("cache", workflow.flags.cache),
flagRow("frozen", workflow.flags.frozen),
flagRow("artifact", workflow.flags.artifact),
flagRow("timeout", workflow.flags.timeout),
flagRow("permissions", workflow.flags.permissions),
flagRow("node pinned", workflow.flags.nodePinned),
].join("");
}
if (selectedEl) {
selectedEl.textContent = workflow
? `当前:${workflow.file} · ${workflow.findings.length} 条命中`
: "—";
}
if (findingsEl) {
findingsEl.innerHTML =
!workflow || workflow.findings.length === 0
? `0 命中:矩阵、xvfb、缓存、artifact、权限与 secret 卫生均通过`
: workflow.findings.map(findingRow).join("");
}
}
function renderSecrets() {
if (!state)
return;
const echoing = state.workflows.filter((row) => row.flags.secretEcho);
if (echoCount)
echoCount.textContent = `${echoing.length} 个 workflow`;
if (secretsEl) {
secretsEl.innerHTML =
echoing.length === 0
? `没有发现明文 echo secret`
: echoing
.map((row) => `
高危
${escapeHtml(row.file)}
secret 出现在 run 的 echo 中
`)
.join("");
}
}
function renderChecks() {
if (!state)
return;
if (checksEl)
checksEl.innerHTML = state.checks.map(checkRow).join("");
if (checkCount) {
const passed = state.checks.filter((check) => check.pass).length;
checkCount.textContent = `${passed}/${state.checks.length} 通过`;
}
if (score) {
score.textContent = `${state.score} / 100`;
score.className = `pill ${state.score === 100 ? "ok-pill" : "bad-pill"}`;
}
if (expectedPill) {
expectedPill.textContent = `expected: ${state.expected.match ? "match" : "mismatch"}`;
expectedPill.className = `pill ${state.expected.match ? "ok-pill" : "bad-pill"}`;
}
if (banner) {
banner.textContent = state.expected.match
? `检测一致:3 个 workflow,${state.totals.findings} 条命中(${state.totals.high} 高 / ${state.totals.medium} 中)`
: `与 expected.json 不一致:${state.expected.mismatches.length} 个文件`;
banner.className = `banner ${state.expected.match ? "ok" : "warn"}`;
}
}
function renderRules() {
if (!state || !rulesEl)
return;
rulesEl.innerHTML = state.rules
.map((rule) => `
${escapeHtml(rule.id)} |
${rule.severity === "high" ? "高" : "中"} |
${escapeHtml(rule.label)} |
`)
.join("");
}
function renderEvents() {
if (!eventsEl || !state)
return;
eventsEl.innerHTML =
state.events.length === 0
? `暂无活动`
: state.events
.slice(0, 8)
.map((row) => `
${time(row.at)}
${escapeHtml(row.kind)}
${escapeHtml(row.detail)}
`)
.join("");
}
function render(next) {
state = next;
renderWorkflow();
renderSecrets();
renderChecks();
renderRules();
renderEvents();
}
function select(id) {
selected = id;
if (state)
renderWorkflow();
}
void window.api.ci.snapshot().then(render);
window.api.ci.onEvent(() => {
void window.api.ci.snapshot().then(render);
});
root
.querySelector('[data-testid="refresh"]')
?.addEventListener("click", async () => {
render(await window.api.ci.refresh());
});
for (const id of ["good", "bad", "fork"]) {
root
.querySelector(`[data-testid="project-${id}"]`)
?.addEventListener("click", () => select(id));
}
window.__prepareShots = async (stage) => {
document.body.dataset.shot = stage;
render(await window.api.ci.scan());
selected = stage;
renderWorkflow();
if (stage === "fork") {
document.querySelector(".secrets")?.scrollIntoView({ block: "start" });
}
else {
document
.querySelector(".workflow-card")
?.scrollIntoView({ block: "start" });
}
};
window.__demo = async () => {
const next = await window.api.ci.snapshot();
state = next;
const find = (id) => next.workflows.find((row) => row.id === id);
return {
score: next.score,
checks: next.checks.length,
passed: next.checks.filter((check) => check.pass).length,
goodFindings: find("good")?.findings.length ?? -1,
badFindings: find("bad")?.findings.length ?? -1,
forkFindings: find("fork")?.findings.length ?? -1,
high: next.totals.high,
echo: next.totals.echo,
matrix: find("good")?.flags.oses.length ?? 0,
expectedMatch: next.expected.match,
mismatches: next.expected.mismatches.length,
workflows: next.workflows.length,
prt: find("fork")?.findings.some((row) => row.ruleId === "R10") ?? false,
};
};
}
//# sourceMappingURL=App.js.map