cognis-digital/cspbuilder

GitHub: cognis-digital/cspbuilder

从页面资源自动生成并审计 Content-Security-Policy 的 CLI 工具,支持 CI 集成与 AI Agent 驱动。

Stars: 0 | Forks: 0

CSPBUILDER # CSPBUILDER ### 从页面资源生成并审计 Content-Security-Policy [![PyPI](https://img.shields.io/pypi/v/cognis-cspbuilder.svg?color=6b46c1)](https://pypi.org/project/cognis-cspbuilder/) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/bf3d7944b0061336.svg)](https://github.com/cognis-digital/cspbuilder/actions) [![License: COCL 1.0](https://img.shields.io/badge/License-COCL%201.0-2b6cb0.svg)](LICENSE) [![Suite](https://img.shields.io/badge/Cognis-Neural%20Suite-6b46c1.svg)](https://github.com/cognis-digital) *Cognis Neural Suite 的一部分。*
``` pip install cognis-cspbuilder cspbuilder scan . # → prioritized findings in seconds ``` ## 用法 — 逐步指南 1. 安装 CLI (Python 3.9+): pip install cspbuilder # 或者:pip install . 从检出的代码安装 2. 构建最小权限策略 — `build` 子命令会扫描 HTML 页面并输出 Content-Security-Policy 头: cspbuilder build page.html --url https://app.example.com 3. 审计现有策略的弱点 — 传入文件或内联头字符串: cspbuilder audit policy.txt cspbuilder audit --policy "default-src 'self'; script-src 'unsafe-inline'" 4. 通过退出代码读取结果:`0` = 通过 / 无可操作的发现,`1` = 高/中级弱点(或策略仍允许内联),`2` = 使用错误。使用 `--format json` 捕获生成的头: cspbuilder build page.html --url https://app.example.com --format json | jq -r .header 5. 在 CI 中检查 CSP 规范 — 当策略出现回归时使构建失败: cspbuilder audit policy.txt || echo "CSP weaknesses detected" ## 目录 - [为什么选择 cspbuilder?](#why) · [功能](#features) · [快速开始](#quick-start) · [示例](#example) · [架构](#architecture) · [AI stack](#ai-stack) · [对比](#how-it-compares) · [集成](#integrations) · [任意位置安装](#install-anywhere) · [相关工具](#related) · [贡献](#contributing) ## 为什么选择 cspbuilder? 发布真正的 CSP `cspbuilder` 是单一用途、可脚本化且可自托管的:将其指向目标,以您的工作流已使用的格式(表格 · JSON · SARIF)获取优先级排序的结果,在 CI 中对其进行限制,并让 agent 通过 MCP 驱动它。
↑ 返回顶部
## 功能 - ✅ 提取资源 - ✅ 构建策略 - ✅ 策略转换为头 - ✅ 解析策略 - ✅ 审计策略 - ✅ 运行于 Linux/macOS/Windows · Docker · devcontainer - ✅ 提供 Python、JavaScript、Go 和 Rust 端口 (`ports/`)
↑ 返回顶部
## 快速开始 ``` pip install cognis-cspbuilder cspbuilder --version cspbuilder scan . # scan current project cspbuilder scan . --format json # machine-readable cspbuilder scan . --fail-on high # CI gate (non-zero exit) ```
↑ 返回顶部
## 示例 ``` $ cspbuilder scan . [HIGH ] CSP-001 example finding (./src/app.py) [MEDIUM ] CSP-002 another signal (./config.yaml) 2 findings · risk score 5 · 38ms ```
↑ 返回顶部
## 架构 ``` flowchart LR IN[target / manifest] --> P[cspbuilder
checks + rules] P --> OUT[findings (JSON / SARIF)] ```
↑ 返回顶部
## 从任何 AI stack 使用 `cspbuilder` 可与每种流行的 AI 使用方式互操作: - **MCP server** — `cspbuilder mcp` (Claude Desktop, Cursor, Cognis.Studio, [uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet)) - **兼容 OpenAI / JSON** — 将 `cspbuilder scan . --format json` 通过管道传递给任何 agent 或 LLM - **LangChain · CrewAI · AutoGen · LlamaIndex** — 一行代码将 CLI/JSON 封装为工具 - **CI / 脚本** — 用于非 AI 流水线的退出代码 + SARIF
↑ 返回顶部
## 对比 | | **Cognis cspbuilder** | csp-evaluator | |---|:---:|:---:| | 可自托管,无需账号 | ✅ | 视情况而定 | | 单一命令,零配置 | ✅ | ⚠️ | | 用于 CI 的 JSON + SARIF | ✅ | 视情况而定 | | 原生 MCP (AI agent) | ✅ | ❌ | | 多语言端口 (JS/Go/Rust) | ✅ | ❌ | | 开源许可 | ✅ COCL | 视情况而定 | *本着 **csp-evaluator** 的精神构建,以 Cognis 的方式重新塑造。遗漏了致谢?提交一个 PR。*
↑ 返回顶部
## 集成 接入您的技术栈:用于代码扫描的 **SARIF**,用于任何场景的 **JSON**,用于 AI agent 的 **MCP server** (`cspbuilder mcp`),以及用于 SIEM/Slack/Jira 的 webhook 转发器。参见 [`docs/INTEGRATIONS.md`](docs/INTEGRATIONS.md)。
↑ 返回顶部
## 安装 — 各种方式,所有平台 ``` pip install "git+https://github.com/cognis-digital/cspbuilder.git" # pip (works today) pipx install "git+https://github.com/cognis-digital/cspbuilder.git" # isolated CLI uv tool install "git+https://github.com/cognis-digital/cspbuilder.git" # uv pip install cognis-cspbuilder # PyPI (when published) docker run --rm ghcr.io/cognis-digital/cspbuilder:latest --help # Docker brew install cognis-digital/tap/cspbuilder # Homebrew tap curl -fsSL https://raw.githubusercontent.com/cognis-digital/cspbuilder/main/install.sh | sh ``` | Linux | macOS | Windows | Docker | Cloud | |---|---|---|---|---| | `scripts/setup-linux.sh` | `scripts/setup-macos.sh` | `scripts/setup-windows.ps1` | `docker run ghcr.io/cognis-digital/cspbuilder` | [DEPLOY.md](docs/DEPLOY.md) (AWS/Azure/GCP/k8s) |
↑ 返回顶部
## 相关的 Cognis 工具 - [`portfan`](https://github.com/cognis-digital/portfan) — 总结并对比 nmap XML,生成优先级排序的、可攻击的发现 - [`subhunt`](https://github.com/cognis-digital/subhunt) — 汇总并去重来自多个来源的子域枚举 - [`dirsight`](https://github.com/cognis-digital/dirsight) — 分析 Web 内容发现输出 (ffuf/gobuster) 为排名的端点 - [`jwtinspect`](https://github.com/cognis-digital/jwtinspect) — 解码 JWT 并检查 alg=none、弱密钥和缺失的声明 - [`corsaudit`](https://github.com/cognis-digital/corsaudit) — 从头信息或配置中检测宽松/错误配置的 CORS - [`headerscan`](https://github.com/cognis-digital/headerscan) — 从响应转储中对 HTTP 安全头 (CSP/HSTS/XFO) 进行 A-F 评级 **探索套件 →** [🗂️ 所有 170+ 工具](https://github.com/cognis-digital/cognis-neural-suite) · [⭐ awesome-cognis](https://github.com/cognis-digital/awesome-cognis) · [🔗 cognis-sources](https://github.com/cognis-digital/cognis-sources) · [🤖 uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet) · [🧠 engram](https://github.com/cognis-digital/engram)
↑ 返回顶部
## 互操作性 `{}` 与包含 300+ 工具的 Cognis 套件组合 — JSON 输入/输出和共享的 兼容 OpenAI 的 `/v1` 主干。参见 **[INTEROP.md](INTEROP.md)** 了解 套件图谱、组合模式和参考栈。 ## 许可证 在 **Cognis Open Collaboration License (COCL) v1.0** 下源代码可见 — 个人、内部评估、研究和教育用途免费;**商业/生产用途需要许可证** (licensing@cognis.digital)。参见 [LICENSE](LICENSE)。
Cognis Digital · Cognis Neural Suite 中的 170+ 工具之一 · Making Tomorrow Better Today
标签:Python, Web安全, 内容安全策略, 可视化界面, 对称加密, 数据可视化, 无后门, 日志审计, 自动化审计, 蓝队分析, 规则仓库, 请求拦截, 逆向工具