shivasurya/code-pathfinder

GitHub: shivasurya/code-pathfinder

一款AI原生的静态代码分析工具,通过构建AST、控制流图和数据流图实现深度漏洞检测,支持MCP协议与AI编程助手深度集成。

Stars: 112 | Forks: 13

Code Pathfinder - AI-Native static code analysis security scanner
[网站](https://codepathfinder.dev/) • [安装](https://codepathfinder.dev/docs/quickstart) • [规则库](https://codepathfinder.dev/registry) • [如何编写规则?](https://codepathfinder.dev/docs/rules) • [VS Code](https://marketplace.visualstudio.com/items?itemName=codepathfinder.secureflow) • [Open VSX](https://open-vsx.org/extension/codepathfinder/secureflow) [![构建](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/08cdbd464b083426.svg)](https://github.com/shivasurya/code-pathfinder/actions/workflows/build.yml) [![VS Code Marketplace](https://img.shields.io/visual-studio-marketplace/v/codepathfinder.secureflow?label=VS%20Code&logo=visualstudiocode)](https://marketplace.visualstudio.com/items?itemName=codepathfinder.secureflow) [![Open VSX](https://img.shields.io/open-vsx/v/codepathfinder/secureflow?label=Open%20VSX&logo=vscodium)](https://open-vsx.org/extension/codepathfinder/secureflow) [![AGPL-3.0 许可证](https://img.shields.io/github/license/shivasurya/code-pathfinder)](https://github.com/shivasurya/code-pathfinder/blob/main/LICENSE) [![询问 DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/shivasurya/code-pathfinder)
### 支持的编程语言 # [Code Pathfinder](https://codepathfinder.dev) 面向现代安全团队的 AI 原生静态代码分析工具。 Code Pathfinder 是一款开源安全扫描器,它为您的代码库构建可查询的图谱。它将代码解析为抽象语法树 (AST),构建控制流图 (CFG) 以跟踪执行路径,并构建数据流图 (DFG) 以追踪数据如何在应用程序中流动。它不像针对每种语言的正则表达式模式匹配,而是将整个代码库索引为结构化数据,让您可以编写查询,在单个规则中追踪跨 Python、[Dockerfiles](https://codepathfinder.dev/registry) 和 [docker-compose](https://codepathfinder.dev/blog/announcing-docker-compose-security-rules) 文件的数据流。 **用途:** - **CVE 检测和漏洞研究**:了解依赖项的使用方式、运行特权以及暴露的攻击面 - **[MCP server](https://codepathfinder.dev/mcp) 用于 AI 编码助手**:为 Claude、GPT 和其他 AI 助手提供代码智能 —— 比 LSP 提供更多上下文,专注于安全和数据流 - **编辑器内安全检查**:在 VS Code 中编写代码时捕获易受攻击的模式 - **CI/CD 流水线**:自动化安全扫描,输出 SARIF 以用于 GitHub Advanced Security,集成 DefectDojo - **自定义安全规则**:使用 Python 编写特定于项目的规则,以检测对您的团队重要的模式 ## 功能特性 - **结构分析**:构建调用图、数据流图和污点跟踪,以[查找漏洞利用路径](https://codepathfinder.dev/blog/static-analysis-isnt-enough-understanding-library-interactions-for-effective-data-flow-tracking),而不仅仅是模式匹配。 - **AI 驱动的分类**:[SecureFlow](https://codepathfinder.dev/secureflow-ai) 在结构分析之上运行 LLM(Claude、GPT、Gemini、Grok、Ollama 等)进行[上下文感知验证](https://codepathfinder.dev/blog/introducing-secureflow-cli-to-hunt-vuln)。 - **IDE 和 CLI**:适用于 [VS Code](https://codepathfinder.dev/docs/quickstart)、命令行以及 CI/CD 流水线。 ## 独特之处 - **调用图和数据流**:索引[函数、端点、数据库调用和数据流](https://codepathfinder.dev/blog/static-analysis-isnt-enough-understanding-library-interactions-for-effective-data-flow-tracking),以追踪从源到汇的漏洞,而不是匹配语法模式。 - **LLM 负责验证,而非检测**:结构分析发现潜在问题;[LLM 对其进行解释和优先级排序](https://github.blog/ai-and-ml/llms/how-ai-enhances-static-application-security-testing-sast/)。这保持了结果的可重复性。 - **您的代码保留在本地**:您[自带 API 密钥](https://codepathfinder.dev/secureflow-ai)并直接与提供商通信。没有供应商端的代码摄取。 ## 应用场景 - **AI 编码助手**:作为 [MCP server](https://codepathfinder.dev/mcp) 运行,为 Claude Code、Cline 或其他 AI 助手提供超越 LSP 提供的深度代码智能(调用图、数据流、安全模式) - **编辑器内**:SecureFlow VS Code 扩展([VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=codepathfinder.secureflow) | [Open VSX](https://open-vsx.org/extension/codepathfinder/secureflow))在您输入时运行安全检查,并在提交前捕获易受攻击的模式 - **命令行**:[SecureFlow CLI](https://www.npmjs.com/package/@codepathfinder/secureflow-cli) 在您的代码库上运行智能体循环,以分析、读取、追踪和验证漏洞 - **CI/CD 流水线**:导出为 SARIF 用于 [GitHub Advanced Security](https://github.com/shivasurya/code-pathfinder),集成 DefectDojo,并支持用于自动化安全门的自定义规则 ## 工具和工作流 **[Code Pathfinder CLI](https://codepathfinder.dev/blog/codeql-oss-alternative)** 核心扫描器和查询引擎。三种运行方式:带有自定义规则的 `scan` 模式用于安全分析,作为 [MCP server](https://codepathfinder.dev/mcp) 用于 AI 编码助手(Claude Code、Cline)的 `serve` 模式,或在 GitHub Actions 和 CI/CD 流水线中的 `ci` 模式。将您的代码库索引为调用图和数据流,然后运行基于 Python 的安全规则来查找从源到汇的漏洞。 **[SecureFlow CLI](https://www.npmjs.com/package/@codepathfinder/secureflow-cli)** AI 驱动的漏洞扫描器,运行多轮分析循环。首先分析您的项目以检测技术栈(Django、Flask、FastAPI 等),然后迭代地请求相关文件,追踪数据流,并使用 LLM(Claude、GPT、Gemini、Grok、Ollama)识别和解释安全问题。导出结果为 JSON、SARIF 或 DefectDojo 格式。 **SecureFlow VS Code 扩展**([Marketplace](https://marketplace.visualstudio.com/items?itemName=codepathfinder.secureflow) | [Open VSX](https://open-vsx.org/extension/codepathfinder/secureflow)) 编辑器内安全分析。右键单击以扫描文件或配置文件,在侧边栏中查看结果,包括严重级别、文件位置和修复建议。使用与 SecureFlow CLI 相同的 AI 模型。在编码时捕获 SQL 注入、XSS、反序列化错误和其他 OWASP Top 10 问题。 **[自定义规则](https://codepathfinder.dev/docs/rules)** 使用 PathFinder SDK 在 Python 中编写安全规则。使用 `find_symbol()` 查询代码图,使用 `get_callees()` 和 `get_callers()` 追踪调用,检查易受攻击的模式。规则在 `scan` 或 `ci` 命令期间运行。请参阅 [规则库](https://codepathfinder.dev/registry) 获取 50 多个示例(SQL 注入、RCE、权限提升、容器配置错误)。 ## 支持的语言 - **[Python](https://codepathfinder.dev/registry/python)**:全面支持安全分析和漏洞检测 - **[Docker](https://codepathfinder.dev/registry/docker)**:Dockerfile 安全扫描 - **[Docker Compose](https://codepathfinder.dev/registry/docker-compose)**:配置分析和安全检查 - **Go**:即将推出 ## 安装 ### Homebrew(推荐) 在 macOS 或 Linux 上安装的最简单方法。从 0.0.34 版本开始可用。 ``` brew install shivasurya/tap/pathfinder ``` ### pip 通过 pip 安装以获取 CLI 二进制文件和用于编写安全规则的 Python SDK。 ``` pip install codepathfinder ``` **验证安装:** ``` # 测试 CLI 二进制文件 pathfinder --version # 测试 Python SDK python -c "from codepathfinder import rule, calls; print('SDK OK')" ``` **支持的平台:** Linux (x86_64, aarch64)、macOS (Intel, Apple Silicon)、Windows (x64) ### Docker 适用于 CI/CD 流水线和容器化工作流。 ``` docker pull shivasurya/code-pathfinder:stable-latest # 运行扫描 docker run --rm -v "./src:/src" \ shivasurya/code-pathfinder:stable-latest \ scan --project /src --rules /src/rules ``` ### 预构建二进制文件 从 [GitHub Releases](https://github.com/shivasurya/code-pathfinder/releases) 下载特定于平台的二进制文件。适用于 Linux (amd64, arm64)、macOS (Intel, Apple Silicon) 和 Windows (x64)。 ``` chmod u+x pathfinder ./pathfinder --help ``` ### 从源代码构建 从源代码构建以获取最新功能。需要 Gradle 和 Go。 ``` git clone https://github.com/shivasurya/code-pathfinder cd code-pathfinder/sast-engine gradle buildGo ./build/go/pathfinder --help ``` ## 使用方法 ### 扫描命令(交互式) ``` # 基本扫描(文本输出至控制台) pathfinder scan --rules rules/ --project /path/to/project # 带详细输出 pathfinder scan --rules rules/ --project . --verbose # 带调试输出 pathfinder scan --rules rules/ --project . --debug # JSON 输出至文件 pathfinder scan --rules rules/ --project . --output json --output-file results.json # SARIF 输出至文件(兼容 GitHub Code Scanning) pathfinder scan --rules rules/ --project . --output sarif --output-file results.sarif # CSV 输出至文件 pathfinder scan --rules rules/ --project . --output csv --output-file results.csv # JSON 输出至 stdout(用于管道传输) pathfinder scan --rules rules/ --project . --output json | jq . # 针对特定严重级别失败 pathfinder scan --rules rules/ --project . --fail-on=critical,high ``` ## GitHub Action 将安全扫描添加到您的 CI/CD 流水线。 **最佳实践:** 固定到特定版本(例如 `@v1.2.0`)而不是 `@main`,以避免破坏性更改。 ``` # .github/workflows/security-scan.yml name: Security Scan on: [push, pull_request] permissions: security-events: write contents: read jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 # Scan with remote Python rulesets - name: Run Python Security Scan uses: shivasurya/code-pathfinder@v1.2.0 with: ruleset: python/deserialization, python/django, python/flask fail-on: critical,high - name: Upload SARIF uses: github/codeql-action/upload-sarif@v4 if: always() with: sarif_file: pathfinder-results.sarif ``` **扫描 Dockerfiles:** ``` - name: Run Docker Security Scan uses: shivasurya/code-pathfinder@v1.2.0 with: ruleset: docker/security, docker/best-practice ``` **使用本地规则:** ``` - name: Run Custom Rules uses: shivasurya/code-pathfinder@v1.2.0 with: rules: python-sdk/examples/owasp_top10.py ``` ### Action 输入 | 输入 | 描述 | 默认值 | |-------|-------------|---------| | `rules` | Python SDK 规则文件或目录的路径 | - | | `ruleset` | 要使用的远程规则集(例如 `python/deserialization, docker/security`)。支持捆绑包或单个规则 ID。 | - | | `project` | 要扫描的源代码路径 | `.` | | `output` | 输出格式:`sarif`、`json`、`csv`、`text` | `sarif` | | `output-file` | 输出文件路径 | `pathfinder-results.sarif` | | `fail-on` | 遇到指定严重级别时失败(例如 `critical,high`) | - | | `verbose` | 启用包含进度和统计信息的详细输出 | `false` | | `debug` | 启用带时间戳的调试诊断 | `false` | | `skip-tests` | 跳过扫描测试文件(test_*.py、*_test.py 等) | `true` | | `refresh-rules` | 强制刷新缓存的规则集(绕过缓存) | `false` | | `disable-metrics` | 禁用匿名使用指标收集 | `false` | | `python-version` | 要使用的 Python 版本 | `3.12` | **注意:** 必须指定 `rules` 或 `ruleset`。 ### 可用的远程规则集 **Python:** - `python/deserialization` - 不安全的 pickle.loads RCE 检测 - `python/django` - Django SQL 注入模式 - `python/flask` - Flask 安全配置错误 **Docker:** - `docker/security` - 严重和高严重性安全问题 - `docker/best-practice` - Dockerfile 优化和最佳实践 - `docker/performance` - 容器镜像的性能优化 ## 致谢 Code Pathfinder 使用 tree-sitter 作为所有语言解析器。 ## 许可证 根据 [AGPL-3.0](https://github.com/shivasurya/code-pathfinder/blob/main/LICENSE) 授权。
标签:AI原生, C2, Code Pathfinder, DevSecOps, Docker安全, EVTX分析, Go安全, GraphQL安全矩阵, MCP, Redis利用, SAST, 上游代理, 代码图谱, 安全专业人员, 安全扫描器, 开源安全工具, 日志审计, 查询引擎, 盲注攻击, 结构化搜索, 自动化payload嵌入, 请求拦截, 软件供应链安全, 远程方法调用, 逆向工具, 逆向工程平台, 错误基检测, 静态代码分析