feat: 遮蔽后台静态产物中的 Taro 指纹
Traefik 把 wechat.app.que01.top 上除 /api、/media 以外的路径直接转发到 Admin 静态 服务器且没有鉴权,因此 /admin/assets/*.js 可以被任意下载。后台产物里的模板 renderer glob 路径(packages/template-*/taro/index.tsx)与按钮尺寸令牌(--taro-button-height) 同样暴露技术栈,此前只遮蔽了 Taro 双端产物。 - mask-taro.cjs 增加 admin 目标,覆盖 apps/admin/dist,接入根脚本 build:admin:preview; - deploy:package 在后台构建后校验 apps/admin/dist,命中指纹即中止打包; - 补充遮蔽目标测试与文档(ADR 0025、README、部署说明、交付清单)。 验证:后台产物遮蔽后 glob key 与运行时查找同步改名;未遮蔽/已遮蔽产物用生产静态 服务器跑同一套后台浏览器测试,失败内容逐字节一致(既有失败与本改动无关);H5 预览 11 项浏览器回归全部通过;admin 构建、lint、typecheck、deploy 与 API 测试通过。
This commit is contained in:
1 parent
9ad2776515
commit
4d1cd8f365
8 files changed
+63
-8
No files matched your search
@@ -3,8 +3,12 @@ import { cp, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createRequire } from "node:module";
|
||||
import { checkPackage } from "./check-package.mjs";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { findLeaks, loadConfig } = require("../../apps/taro/config/mask-taro.cjs");
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const timestamp = new Date().toISOString().replace(/\D/g, "").slice(0, 14);
|
||||
const git = spawnSync("git", ["rev-parse", "--short=12", "HEAD"], { cwd: root, encoding: "utf8" });
|
||||
@@ -19,6 +23,21 @@ function run(command, args) {
|
||||
if (result.status !== 0) process.exit(result.status ?? 1);
|
||||
}
|
||||
|
||||
/** 发布产物对外可下载,出现框架指纹即视为发布配置错误。 */
|
||||
function assertNoStackFingerprint(directory) {
|
||||
const config = loadConfig();
|
||||
if (!config.enabled) return;
|
||||
const leaks = findLeaks(path.join(root, directory), config);
|
||||
if (!leaks.length) return;
|
||||
throw new Error(
|
||||
`${directory} 仍含技术栈指纹,请通过包内构建脚本产出:\n` +
|
||||
leaks
|
||||
.slice(0, 10)
|
||||
.map((leak) => " - " + leak)
|
||||
.join("\n"),
|
||||
);
|
||||
}
|
||||
|
||||
async function listFiles(directory, prefix = "") {
|
||||
const files = [];
|
||||
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
||||
@@ -142,6 +161,7 @@ async function main() {
|
||||
}
|
||||
|
||||
run("pnpm", ["build:admin:preview"]);
|
||||
assertNoStackFingerprint("apps/admin/dist");
|
||||
run("pnpm", ["--filter", "@personal-brand/config", "build"]);
|
||||
run("pnpm", ["--filter", "@personal-brand/types", "build"]);
|
||||
run("pnpm", ["--filter", "@personal-brand/validation", "build"]);
|
||||
|
||||
Reference in new issue
Block a user