# 46-csp-navigation-integrity / app CSP 与导航完整性实验室:真实的 inline/eval/fetch/image 四类 CSP 探针、 导航白名单与 `window.open` 拒绝、资源 SHA-256 完整性校验、依赖精确版本检查。 ## 运行 ```bash pnpm --filter @tutorial/46-csp-navigation-integrity-app start pnpm --filter @tutorial/46-csp-navigation-integrity-app smoke pnpm --filter @tutorial/46-csp-navigation-integrity-app shots ``` ## smoke 输出 ```json {"evt":"smoke","ok":true,"score":100,"checks":10,"passed":10, "violations":4,"blockedProbes":4, "policyRows":7,"policyAllowed":3, "attempts":2,"observedBlocked":2, "currentUrl":"http://localhost:5173/", "integrityOk":true,"tamperedOk":false,"manifestVersion":1, "isPackaged":false,"asar":false,"events":10} ``` ## 结构 - `shared/ipc.ts`:通道、快照类型、导航策略与 CSP 解析 - `main/index.ts`:导航/新窗口/webview 防线、CSP 探针调度、SHA-256 校验 - `preload/index.ts`:`integrity` 白名单方法 + 事件 - `src/App.ts`:CSP 工作台、导航判定、完整性、检查表与打包态说明 - `resources/`:`notice.txt` 与 `manifest.json` ## testid | testid | 用途 | | --- | --- | | `score` / `checks` / `check-count` | 10 项防线 | | `run-csp` / `csp-results` / `violations` | CSP 探针与违规 | | `open-evil` / `nav-evil` / `nav-http` | 导航尝试 | | `nav-policy` / `nav-attempts` | 策略与实际结果 | | `integrity` / `tamper` | 哈希校验与篡改副本 | | `packaging` | 是否打包 / ASAR / fuses | ## 已知限制 - 开发态没有 ASAR,fuses 未读取;界面如实显示 `dev-only`。 - 拦截所有非白名单导航,包括用户主动点击的外链;真实产品应改用系统浏览器打开。 - 资源哈希只覆盖 `notice.txt`,不是 ASAR 级完整性校验。