fix: 收口模板契约与安全门禁
统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
This commit is contained in:
1 parent
456171aa85
commit
4f0b50c7f1
84 files changed
+7367
-5180
No files matched your search
@@ -1,3 +1,6 @@
|
||||
import crypto from "node:crypto";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import ts from "typescript";
|
||||
|
||||
// 静态检查不推断运行时成功;未知表达式保留为 review。
|
||||
@@ -409,3 +412,68 @@ export function applyManualReview(reports, reviews, reviewScope) {
|
||||
}
|
||||
return reports;
|
||||
}
|
||||
|
||||
export function applyCompletionEvidence(reports, registry, root) {
|
||||
if (registry === undefined) {
|
||||
for (const report of reports) report.completionStatus = "unverified";
|
||||
return { completionStatus: "unverified", reports };
|
||||
}
|
||||
if (
|
||||
!registry ||
|
||||
registry.schemaVersion !== 1 ||
|
||||
registry.scope !== "模板完成证据登记,保留命令、日志与产物哈希" ||
|
||||
!registry.templates ||
|
||||
typeof registry.templates !== "object" ||
|
||||
Array.isArray(registry.templates)
|
||||
) {
|
||||
throw new Error("Completion evidence registry has an unsupported schema");
|
||||
}
|
||||
|
||||
const expectedTemplates = new Set(reports.map((report) => report.template));
|
||||
const registeredTemplates = new Set(Object.keys(registry.templates));
|
||||
const rootPath = path.resolve(root);
|
||||
const insideRoot = (value) => {
|
||||
const resolved = path.resolve(rootPath, value);
|
||||
if (resolved !== rootPath && !resolved.startsWith(rootPath + path.sep)) return null;
|
||||
return resolved;
|
||||
};
|
||||
const validEvidence = (evidence) => {
|
||||
if (!evidence || evidence.status !== "passed" || !Array.isArray(evidence.commands)) return null;
|
||||
if (!evidence.commands.length || evidence.commands.some((command) => !command.trim()))
|
||||
return null;
|
||||
if (!Array.isArray(evidence.artifacts) || !evidence.artifacts.length) return null;
|
||||
return evidence;
|
||||
};
|
||||
|
||||
let complete = true;
|
||||
for (const report of reports) {
|
||||
const evidence = registry.templates[report.template] ?? {};
|
||||
const completionIssues = [];
|
||||
for (const key of report.requiredEvidence) {
|
||||
const item = validEvidence(evidence[key]);
|
||||
if (!item) {
|
||||
completionIssues.push(`${key}: missing or invalid passed evidence`);
|
||||
continue;
|
||||
}
|
||||
for (const artifact of item.artifacts) {
|
||||
if (!artifact?.path || !/^[a-f0-9]{64}$/.test(artifact.sha256 ?? "")) {
|
||||
completionIssues.push(`${key}: artifact path or sha256 is invalid`);
|
||||
continue;
|
||||
}
|
||||
const filePath = insideRoot(artifact.path);
|
||||
if (!filePath || !fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
|
||||
completionIssues.push(`${key}: artifact does not exist: ${artifact.path}`);
|
||||
continue;
|
||||
}
|
||||
const hash = crypto.createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
|
||||
if (hash !== artifact.sha256)
|
||||
completionIssues.push(`${key}: artifact checksum mismatch: ${artifact.path}`);
|
||||
}
|
||||
}
|
||||
report.evidence = evidence;
|
||||
report.completionIssues = completionIssues;
|
||||
report.completionStatus = completionIssues.length ? "incomplete" : "complete";
|
||||
if (completionIssues.length) complete = false;
|
||||
}
|
||||
return { completionStatus: complete ? "complete" : "incomplete", reports };
|
||||
}
|
||||
Reference in new issue
Block a user