IWEBai/railo

GitHub: IWEBai/railo

一个确定性的安全漏洞自动修复工具,在 PR 合并时检测并自动修复 SQL 注入、硬编码密钥、XSS 等常见安全问题,将安全发现转化为代码修复而非积压事项。

Stars: 6 | Forks: 1

# IWEB 出品的 Railo **自动修复 PR 中的安全漏洞。** Railo 是一个确定性的安全补丁机器人,在合并时强制执行合规性——因此安全发现变成了合并的修复,而不是积压事项。 随着 AI 增加 PR 的数量,Railo 将安全债务保持为零:每个发现都会得到修复,每个修复都会被合并。 **定位:** _你工作流中的固定点,在合并前检测并纠正安全问题——没有 AI,无需等待,没有积压。_ [![Tests](https://img.shields.io/badge/tests-151%20passed-brightgreen)](https://github.com/IWEBai/fixpoint) [![Python](https://img.shields.io/badge/python-3.12+-blue)](https://python.org) [![License](https://img.shields.io/badge/license-MIT-green)](./LICENSE) [![Marketplace](https://img.shields.io/badge/GitHub-Marketplace-blue)](https://github.com/marketplace/actions/fixpoint-auto-fix-security-vulnerabilities) **作为 GitHub App 安装(免费 beta):** [安装 Railo](https://github.com/apps/railo-cloud/installations/new) — 一键安装到你的组织或仓库。 ## Beta 测试 (v1.1.0) **早期采用者免费 beta。** 无需付费,无需 Marketplace 注册——安装即可使用。 我们邀请早期用户在更广泛发布之前测试 Railo。 | 预期内容 | 详情 | | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **稳定性** | 核心流程已测试;151 个测试通过(Windows 上的 Semgrep 有 3 个跳过)。可能仍存在一些边缘情况。 | | **平台** | GitHub Action & CLI: Linux, Mac。 Semgrep: 不支持 Windows。 | | **模式** | 从 `mode: warn` 开始 — 在启用 enforce 之前审查建议的修复。 | | **反馈** | 在 [Discussions](https://github.com/IWEBai/fixpoint/discussions) 或 [Issues](https://github.com/IWEBai/fixpoint/issues) 中报告问题、别扭的工作流程或“我该如何……?” | **快速测试:** Fork [fixpoint-demo](https://github.com/IWEBai/fixpoint-demo),添加来自 [Quick Start](#quick-start) 的工作流,打开一个包含漏洞代码的 PR。Railo 将发表评论或进行修复。 **支持:** [support@fixpoint.dev](mailto:support@fixpoint.dev) · **隐私:** [隐私政策](./docs/PRIVACY_POLICY.md) 有关完整的发布说明和反馈提示,请参阅 [Beta Tester Notes](./docs/BETA_TESTER_NOTES.md)。 ## 修复 PR 如何工作(第一阶段) - Railo 扫描 PR 分支,但在 enforce 模式下永远不会提交到该分支。 - 如果修复是安全的,Railo 会从当前 PR 状态创建一个 **新分支**(`railo/fix-...`)。 - Railo 会打开一个单独的 **Fix PR → base branch**,并应用所有修复。 - 原始 PR 保持不变;开发者可以独立合并 Fix PR。 为什么这很重要:开发者感到被帮助,而不是被打断——就像 Dependabot 修复 PR 一样。 ## 它修复什么 | 漏洞 | 检测 | 自动修复 | | --------------------- | ----------------------------------------------------- | --------------------------- | | **SQL Injection** | f-strings, concatenation, `.format()`, `%` formatting | ✅ 参数化查询 (Parameterized queries) | | **硬编码机密 (Hardcoded Secrets)** | 密码, API keys, tokens, database URIs | ✅ `os.environ.get()` | | **XSS (Templates)** | `\|safe` filter, `autoescape off` | ✅ 移除不安全模式 | | **XSS (Python)** | `mark_safe()`, `SafeString()` | ✅ 替换为 `escape()` | | **命令注入 (Command Injection)** | `os.system()`, `subprocess` with `shell=True` | ✅ 基于列表的 `subprocess` | | **路径遍历 (Path Traversal)** | `os.path.join` with user input | ✅ 路径验证 | | **SSRF** | `requests.get()`, `urlopen` with dynamic URL | ⚠️ 检测 + 指导 | | **JS/TS eval** | `eval()` with user input | ⚠️ 检测 + 指导 | | **JS/TS secrets** | `apiKey = "xxx"` | ✅ `process.env.API_KEY` | | **JS/TS DOM XSS** | `innerHTML =` with user input | ✅ `textContent =` | ## 理念 - **确定性优先:** 相同的输入 → 相同的输出。没有 AI 幻觉。 - **修复不使用 AI/LLM:** 所有修复都是基于规则且可审计的。 - **通过透明建立信任:** 从 warn 模式开始,准备好后升级到 enforce。 - **安全胜于速度:** 最大差异限制,可选测试运行,每个发现都带有 CWE/OWASP 标签。 ## 开源核心边界(简述) - **OSS(采用引擎):** 扫描引擎、确定性基础修复器/规则、GitHub Action/CLI、基线模式、安全护栏、SARIF 导出、本地配置(`.fixpoint.yml`)。 - **企业版(保留):** 组织仪表板、策略/例外 UI、多仓库分析、合规性导出(SOC2/ISO)、高级规则包、集中式例外、SSO/RBAC、托管扫描服务。 - 核心保持 MIT 许可;未来的 SaaS/企业代码将位于 `fixpoint-cloud/` 和 `fixpoint-enterprise/` 下。 ## 快速开始 添加到 `.github/workflows/fixpoint.yml`: ``` name: Fixpoint on: pull_request: types: [opened, synchronize, reopened] permissions: contents: write pull-requests: write statuses: write jobs: fixpoint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} fetch-depth: 0 - name: Fixpoint uses: IWEBai/fixpoint@v1 with: mode: warn # Start with warn, graduate to enforce base_branch: ${{ github.base_ref }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` **就这样。** Fixpoint 将扫描每个 PR 的漏洞。 ## 示例修复 ### SQL 注入 ``` # 修复前(有漏洞) query = f"SELECT * FROM users WHERE email = '{email}'" cursor.execute(query) # 修复后(自动修复) query = "SELECT * FROM users WHERE email = %s" cursor.execute(query, (email,)) ``` ### 硬编码机密 (Hardcoded Secrets) ``` # 修复前(有漏洞) api_key = "sk_live_abc123def456" # 修复后(自动修复) api_key = os.environ.get("API_KEY") ``` ### 模板中的 XSS (XSS in Templates) ```

{{ user_input|safe }}

{{ user_input }}

``` ### Python 中的 XSS (XSS in Python) ``` # 修复前(有漏洞) return mark_safe(user_input) # 修复后(自动修复) return escape(user_input) ``` ### 命令注入 (Command Injection) ``` # 修复前(有漏洞) os.system(user_input) # 修复后(自动修复) subprocess.run(shlex.split(user_input), shell=False) ``` ### 路径遍历 (Path Traversal) ``` # 修复前(有漏洞) path = os.path.join(base_dir, user_input) # 修复后(自动修复) path = os.path.join(base_dir, user_input) if not os.path.realpath(path).startswith(os.path.realpath(base_dir)): raise PermissionError("Path traversal denied") ``` ### JS/TS 硬编码机密 (JS/TS Hardcoded Secrets) ``` // Before (vulnerable) const apiKey = "sk_live_abc123"; // After (auto-fixed) const apiKey = process.env.API_KEY || ""; ``` ### JS/TS DOM XSS ``` // Before (vulnerable) el.innerHTML = userInput; // After (auto-fixed) el.textContent = userInput; ``` ## 模式 ### 警告模式 (Warn Mode)(默认) ``` mode: warn ``` - 发布带有建议修复的 PR 评论 - 将状态检查设置为 **FAIL** - 不进行提交 - 非常适合建立信任 ### 强制模式 (Enforce Mode) ``` mode: enforce ``` - 自动应用修复 - 提交到 PR 分支 - 将状态检查设置为 **PASS** - 适用于受信任的生产用途 **建议:** 从 `warn` 模式开始,审查修复,然后升级到 `enforce`。 ## 状态检查 Fixpoint 设置 GitHub 状态检查(`fixpoint/compliance`): | 状态 | 含义 | | ----------- | ------------------------------------ | | ✅ **PASS** | 未发现漏洞 | | ❌ **FAIL** | 发现漏洞(warn 模式) | | ✅ **PASS** | 漏洞已修复(enforce 模式) | ### 在失败时阻止合并 1. 转到 **Settings → Branches → Branch protection rules** 2. 启用 **"Require status checks to pass before merging"** 3. 选择: `fixpoint/compliance` 4. 保存 现在,有安全问题的 PR 在修复之前无法合并。 ## 配置 ### 仓库配置(`.fixpoint.yml`) 在仓库根目录中创建 `.fixpoint.yml` 以自定义安全护栏。 新增:预设和 CLI 生成器,让这一切变得毫不费力。 **预设配置** - **starter**: 仅警告,低噪音 - **balanced**: 强制安全修复,对风险较高的转换发出警告 - **strict**: 强制执行更多规则,更严格的安全护栏 - **tailored**: 团队特定默认值(参见 core/config.py 中的 preset) 从预设生成配置: ``` python main.py config init --preset starter ``` 这会将 `.fixpoint.yml` 写入当前目录。使用 `--repo` 指定另一个路径,使用 `--force` 进行覆盖。 **示例(balanced 预设)** ``` max_diff_lines: 400 max_files_changed: 8 max_runtime_seconds: 90 test_before_commit: false test_command: "pytest" allow_dependency_changes: false sensitive_paths_allowlist: [] rules: enabled: - sqli - secrets - xss - command-injection - path-traversal - ssrf - eval - dom-xss enforce_per_rule: sqli: enforce secrets: enforce dom-xss: enforce xss: warn command-injection: warn path-traversal: warn ssrf: warn eval: warn severity_threshold: ERROR # 特定目录的 Longest-prefix policies directory_policies: "src/critical/": severity_threshold: WARNING enforce_per_rule: xss: warn format_after_patch: true max_format_expansion: 0.2 ``` 或使用 env vars: `FIXPOINT_MAX_DIFF_LINES`, `FIXPOINT_TEST_BEFORE_COMMIT`, `FIXPOINT_TEST_COMMAND`。 **Schema 验证** Fixpoint 在运行时验证 `.fixpoint.yml`,并针对错误字段或类型报告友好的、行级错误。 **基线模式(噪音抑制)** 基线模式过滤预先存在的发现,以便只显示新问题。 ``` # 在 commit 创建 baseline python main.py baseline create --sha ``` 在 `.fixpoint.yml` 中启用: ``` baseline_mode: true baseline_sha: "" baseline_max_age_days: 30 # optional rebaseline window (0 = never) ``` **GitHub Action** — 作为输入传递: ``` - uses: IWEBai/fixpoint@v1 with: mode: warn max_diff_lines: "500" test_before_commit: "true" test_command: "pytest" ``` PR 评论包含每个发现的 **CWE/OWASP 标签**(例如 `CWE-89 | A03:2021`)。 ### 忽略文件 在仓库根目录中创建 `.fixpointignore`: ``` # .fixpointignore tests/ test_*.py migrations/ third_party/ *.test.py ``` ## 检测详情 ### SQL 注入 (Python) 检测不安全的 SQL 构造模式: | 模式 | 示例 | | -------------- | ----------------------------- | | f-strings | `f"SELECT * WHERE id = {id}"` | | Concatenation | `"SELECT * WHERE id = " + id` | | `.format()` | `"SELECT {}".format(id)` | | `%` formatting | `"SELECT %s" % id` | 支持变量名: `query`, `sql`, `stmt`, `command` 等。 支持游标名: `cursor`, `cur`, `db`, `conn`, `c` 等。 ### 硬编码机密 (Hardcoded Secrets) 检测代码中的机密: | 类型 | 示例 | | ------------- | ------------------------------------- | | AWS Keys | `AKIA...` pattern | | GitHub Tokens | `ghp_...`, `gho_...` | | Slack Tokens | `xoxb-...` | | Stripe Keys | `sk_live_...` | | Database URIs | `postgres://user:pass@...` | | Generic | `password = "..."`, `api_key = "..."` | ### XSS (Cross-Site Scripting) **在模板中 (Jinja2/Django):** - `{{ variable|safe }}` - The `|safe` filter - `{% autoescape off %}` - Disabled escaping **在 Python 中:** - `mark_safe(variable)` - Django mark_safe - `SafeString(variable)` - Django SafeString - `Markup(variable)` - Flask/Jinja2 Markup ### JavaScript/TypeScript | 问题 | 模式 | 修复 | | ----------- | -------------------------- | --------------------------------------------------------- | | **eval** | `eval(userInput)` | 仅检测;指导建议 JSON.parse 或移除 | | **Secrets** | `apiKey = "sk_live_xxx"` | `process.env.API_KEY` | | **DOM XSS** | `el.innerHTML = userInput` | `el.textContent = userInput` | ## CLI 用法 ``` # 安装 pip install -r requirements.txt pip install semgrep # Linux/Mac only - required for scanning # Warn mode (扫描 .py, .js, .ts, .jsx, .tsx) python main.py /path/to/repo --warn-mode # Enforce mode python main.py /path/to/repo # PR diff mode python main.py /path/to/repo --pr-mode --base-ref main --head-ref feature ``` ## 自托管 Webhook 对于本地部署: ``` # 配置 cp .env.example .env # 使用你的设置编辑 .env # 运行 python webhook_server.py ``` 配置 GitHub webhook: - **URL:** `https://your-domain.com/webhook` - **Events:** `pull_request` (opened, synchronize) - **Secret:** Your `WEBHOOK_SECRET` 有关详细信息,请参阅 [API Reference](./docs/API_REFERENCE.md)。 ## 它不能做什么 - ❌ 修复任意错误 - ❌ 重构代码 - ❌ 自动合并 PR - ❌ 生成创造性的修复 - ❌ 使用 AI/LLMs **仅限确定性的、可验证的、合规安全的更改。** ## 系统要求 - Python 3.12+ - Semgrep(在 GitHub Action 和 Docker 中自动安装;CLI 需单独安装: `pip install semgrep`) - GitHub repository - GitHub Actions(或自托管 webhook) - 支持的文件: `.py`, `.js`, `.ts`, `.jsx`, `.tsx` ## 文档 - [**iwebai.space**](https://www.iwebai.space) - IWEB 网站 - [**r/IWEBai**](https://www.reddit.com/r/IWEBai/) - Reddit 社区 - [Demo Repository](https://github.com/IWEBai/fixpoint-demo) - 使用漏洞代码示例试用 Fixpoint - [**Beta Tester Notes**](./docs/BETA_TESTER_NOTES.md) - 测试人员的发布说明和反馈提示 - [Introduction](./docs/INTRODUCTION.md) - 为什么选择 Fixpoint? - [Getting Started](./docs/GETTING_STARTED.md) - 完整设置指南 - [API Reference](./docs/API_REFERENCE.md) - Webhook API - [Environment Variables](./docs/ENVIRONMENT_VARIABLES.md) - 配置 - [Roadmap](./ROADMAP.md) - 下一步计划 ## 许可证 MIT License - 详见 [LICENSE](./LICENSE)。 ## 正在使用 Fixpoint? **请告诉我们 — 这有助于我们改进并规划下一步构建什么。** | 我们希望... | 如何 | | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **知道谁在使用它** | [**"Who's using Fixpoint?"**](https://github.com/IWEBai/fixpoint/discussions/categories/whos-using-fixpoint) 中回复你的公司/仓库(可选)。 | | **获取你的反馈** | 打开一个 [**Issue**](https://github.com/IWEBai/fixpoint/issues) 或 [**Discussion**](https://github.com/IWEBai/fixpoint/discussions) — 错误、功能想法或“我该如何……?” | | **帮助我们构建** | **你会为托管版本付费吗?** 什么让它物有所值?[在此回复](https://github.com/IWEBai/fixpoint/discussions) — 你的意见塑造我们的路线图。 | | **为你提供更多** | 需要托管版 Fixpoint (SaaS) 或企业支持?[**联系我们**](https://github.com/IWEBai/fixpoint/discussions/categories/general) — 我们正在构建付费选项。 | ## 支持与社区 - **网站:** [iwebai.space](https://www.iwebai.space) - **社区:** [r/IWEBai on Reddit](https://www.reddit.com/r/IWEBai/) - **贡献:** [CONTRIBUTING.md](CONTRIBUTING.md) - **安全:** [SECURITY.md](SECURITY.md) (报告漏洞) - **问题:** [GitHub Issues](https://github.com/IWEBai/fixpoint/issues) - **讨论:** [GitHub Discussions](https://github.com/IWEBai/fixpoint/discussions) _Fixpoint by [IWEB](https://www.iwebai.space) — 因为安全不应拖慢你的脚步。_
标签:CI/CD 安全, CISA项目, DevSecOps, GitHub Action, GitHub App, PR 自动化, Python, SAST, Semgrep, WordPress安全扫描, XSS, 上游代理, 代码安全, 代码审查, 安全左移, 数据投毒防御, 文档结构分析, 无后门, 模块化设计, 漏洞情报, 漏洞枚举, 盲注攻击, 硬编码密钥, 端点安全, 自动化修复, 补丁管理, 跨站脚本攻击, 软件供应链安全, 远程方法调用, 逆向工具