使用 CodeMender 保护您的应用

1. 准备工作

⏱️ 时长:03:00

欢迎参加 Google Cloud 的 Gemini Enterprise Agent Platform 上的使用 CodeMender 保护应用安全实操 Codelab。

在本研讨会中,您将扮演 Cloud Security Engineer 的角色,负责审计和保护 OWASP Juice Shop。OWASP Juice Shop 是一个业界标准的 Web 应用,采用 Node.js、Express、TypeScript 和 Angular 构建,故意留有漏洞。

传统的安全扫描工具 (SAST/DAST) 会向开发团队提供数千个静态安全发现结果,误报率高,且无法提供可操作的代码修复。开发者需要花费数小时来分类日志、跟踪数据流,并手动编写经常会破坏现有应用行为的补丁。

CodeMender 围绕 Google 的 Gemini LLM 构建了一个经过微调的智能体 Harness,从而彻底改变了代码安全。CodeMender 采用 Google DeepMind 设计的提示、专业安全技能和多智能体编排,充当自主 AI 安全联合开发者,直接在本地源代码库中发现、验证和修复软件漏洞。

前提条件

  • 基本了解 Web 应用漏洞(OWASP 十大漏洞,例如 SQL 注入和 XSS)
  • 基本熟悉 JavaScript/TypeScript 和 Node.js 应用
  • 基本熟悉命令行界面 (CLI) 工具

学习内容

  • 如何在 Google Cloud Shell 中设置、验证和初始化 CodeMender (cm) CLI。
  • 如何自主扫描代码库以发现可利用的漏洞 (cm find)。
  • 如何在隔离沙盒中验证漏洞并检查验证工件 (cm verify)。
  • 如何自主合成、测试和应用情境感知安全补丁 (cm fix)。
  • 如何审核令牌遥测数据并导出多种格式的合规性报告(cm stats、cm report)。

所需条件

  • 启用了结算功能的 Google Cloud 项目
  • 已连接到有效项目的 Google Cloud Shell(包含预安装的 gcloud、git 和 Node.js 18+)
  • 起始代码库:OWASP Juice Shop GitHub 代码库

2. CodeMender 架构简介

⏱️ 时长:04:00

在深入了解代码扫描和修复之前,我们先来了解一下 CodeMender 如何根据 Google Cloud 官方架构标准在 Gemini Enterprise Agent Platform 中运行。

系统架构:代理和客户端守护程序

CodeMender 自主修复引擎工作流

从用户角度来看,CodeMender 包含两个主要架构组件:

托管式多智能体平台:在 Google Cloud 上运行的托管式多智能体系统,负责执行核心安全业务逻辑、LLM 提示词工程和安全推理。

本地客户端 CLI 和沙盒守护程序 (cm):在 Google Cloud Shell 中运行的客户端,既充当 CLI(用于发出 cm find、cm verify、cm fix 等命令),又充当本地守护程序(用于在隔离的进程级沙盒中代表代理安全地执行命令)。

3 项核心修复功能

CodeMender 自主修复流程

CodeMender 通过三个集成阶段来处理代码安全问题:

Find Vulnerabilities (cm find):在智能体的引导下,使用 LLM 扫描代码库,并利用专门的安全工具和提示词工程,让模型专注于发现安全缺陷。(或者,也可以从外部安全扫描工具导入发现结果)。

验证漏洞 (cm verify):在本地构建代码,并尝试利用发现的缺陷来验证其是否可被利用。这样可以消除假正例,并在 .exploit/(info.yaml、PLAN.md、LOG.md、exploit.sh、REPORT.md)中生成持久的工作区验证工件。

修复漏洞 (cm fix):合成语言感知型源代码补丁,并通过在本地沙盒中运行项目构建和回归测试套件 (npm test) 来验证这些补丁。

3. 设置 OWASP Juice Shop 环境

⏱️ 时长:05:00

在此步骤中,您将打开 Google Cloud 终端环境并提取目标应用代码库。

第 1 步:在 Google Cloud 控制台中打开 Cloud Shell

在浏览器中前往 Google Cloud 控制台。

在顶部导航栏中,点击激活 Cloud Shell 按钮(图标 >_)。

Cloud Shell 提供了一个基于浏览器的 Linux 终端,其中预安装了 gcloud、git 和 Node.js,并已通过身份验证。

第 2 步:克隆 OWASP Juice Shop 代码库

在 Cloud Shell 或本地终端中,克隆 OWASP Juice Shop 代码库:

git clone https://github.com/juice-shop/juice-shop.git --depth 1
cd juice-shop

第 3 步:检查关键应用文件

OWASP Juice Shop 在后端使用 Express.js 和 TypeScript 模块。快速浏览一下目录结构:

ls -la routes/ lib/

请注意处理身份验证、用户查询和购物车管理的关键路由文件:

routes/login.ts:处理用户身份验证和原始 SQL 查询执行。

routes/search.ts:处理商品搜索和回答渲染。

routes/basket.ts:处理用户购物车检索。

routes/trackOrder.ts:通过 NoSQL 查询处理订单跟踪。

lib/xml.ts:处理 XML 解析和文件上传。

lib/insecurity.ts:用于会话令牌和加密的辅助实用程序。

4. 安装 CodeMender CLI (cm) 并对 GCP 凭据进行身份验证

⏱️ 时长:08:00

在此步骤中,您将启用所需的 Google Cloud API、使用 gcloud 授予 IAM 权限、下载并安装 cm CLI 二进制文件,以及配置应用默认凭证 (ADC)。

第 1 步:通过 gcloud 启用所需的 Google Cloud API

CodeMender 需要 Gemini Enterprise Agent Platform 上的 Agent Platform API (aiplatform.googleapis.com) 和 Cloud Resource Manager API (cloudresourcemanager.googleapis.com)。

在 Cloud Shell 或终端中,检索您的有效项目 ID(或查看 Google Cloud 控制台顶部的项目下拉菜单),然后启用所需的服务 API:

# Automatically retrieve and set your active Google Cloud project ID
export PROJECT_ID=$(gcloud config get-value project)
gcloud config set project ${PROJECT_ID}

# Enable required Google Cloud APIs
gcloud services enable \
 aiplatform.googleapis.com \
 cloudresourcemanager.googleapis.com \
 serviceusage.googleapis.com \
 --project=${PROJECT_ID}

验证是否已启用上述 API:

gcloud services list --enabled --filter="name:(aiplatform.googleapis.com OR cloudresourcemanager.googleapis.com)"

第 2 步:通过 gcloud 授予 IAM 权限

如需与 CodeMender 云推理引擎交互,用户和服务账号必须拥有 roles/aiplatform.user (Agent Platform User) IAM 角色。

通过 CLI 向您的用户账号授予 IAM 角色

# Get your active authenticated gcloud account email
USER_EMAIL=$(gcloud config get-value account)

# Add IAM policy binding for user account
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
 --member="user:${USER_EMAIL}" \
 --role="roles/aiplatform.user"

第 3 步:cm 在 Cloud Shell 中下载并安装 CLI

在 Google Cloud Shell 中,用户数据会永久存储在 $HOME 目录中。执行以下命令,将 cm 安装到 ~/bin 中,而无需 sudo。您仍处于上一部分中的 ~/juice-shop,因此这些命令会下载到临时目录中,并在之后进行清理。这样,Juice Shop 代码库中就不会出现安装程序文件:

# Download into a temporary directory so nothing lands in the Juice Shop repository
CM_TMP=$(mktemp -d)
curl -L -o "${CM_TMP}/cm-linux-amd64.zip" "https://artifactregistry.googleapis.com/download/v1/projects/cmoc-prod/locations/us/repositories/codemender-cli-production/files/cm:stable:cm-linux-amd64.zip:download?alt=media"
unzip -o "${CM_TMP}/cm-linux-amd64.zip" -d "${CM_TMP}"

# Install into your persistent ~/bin directory and clean up
mkdir -p ~/bin
install -m 0755 "${CM_TMP}/cm" ~/bin/cm
rm -rf "${CM_TMP}"

# Add ~/bin to PATH for this session and future Cloud Shell sessions
export PATH="$HOME/bin:$PATH"
grep -qxF 'export PATH="$HOME/bin:$PATH"' ~/.bashrc || echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc

第 4 步:验证 cm CLI 安装

运行 cm --version 以验证 CLI 二进制文件是否已正确安装:

cm --version

预期输出:

cm version 0.17.0

第 5 步:配置 Google Cloud 应用默认凭证 (ADC)

配置 Google Cloud 应用默认凭证 (ADC),以便 cm 能够对发送到 Cloud 推理引擎 的请求进行身份验证:

gcloud auth application-default login

系统会显示一个名为为 Cloud Shell 提供授权的授权模态对话框。点击授权以授予访问权限。

5. 初始化并验证 CodeMender 工作区

⏱️ 时长:03:00

现在,cm 已安装并完成身份验证,您将在目标项目目录中初始化 CodeMender 工作区,并验证环境设置。

第 1 步:初始化 CodeMender 工作区 (cm init)

从项目目录的根目录运行 cm init,以初始化本地状态跟踪文件并建立基准配置:

cm init

输出:

✅ Initialized CodeMender workspace at /home/user/.codemender

第 2 步:运行端到端健康状况诊断 (cm health)

在启动代理会话之前,请运行 cm health 以验证您的凭证、配置、可达性和授权:

cm health

输出:

CodeMender Health Check
───────────────────────
 Backend:   iapi
 Endpoint:  https://aiplatform.googleapis.com
 Location:  global
 Project:   my-gcp-project

 ✓ credentials     passed   (0ms)  Token acquired for project "my-gcp-project"
 ✓ config          passed   (0ms)  Configuration valid (backend "iapi")
 ✓ reachability    passed   (250ms)  Endpoint https://aiplatform.googleapis.com responded
 ✓ authorization   passed   (68ms)  Caller authorized for project "my-gcp-project"

Status: HEALTHY (exit code 0, 319ms)

第 3 步:了解配置参数 (config.yaml)

CodeMender 会在 .codemender/config.yaml(或 ~/.codemender/config.yaml)中创建一个工作区配置文件。此文件定义了政策边界、文件包含规则和测试验证钩子:

# CodeMender CLI configuration.
# The server endpoint is baked in at build time (see build profiles).
# Override it here only if you need a different endpoint.

server: {}
location: "global"         # Service location: "global" (default), "us", "eu", or "us-central1" (overridden by $CM_LOCATION)

# Customer-supplied team identifier sent as the X-CodeMender-Team-Id
# telemetry header. Overridden by --team-id flag or $CM_TEAM_ID env var.
# Max 63 chars, must match [A-Za-z0-9._-]. Omit to skip the header.
# team_id: "acme-security"

scan:
 extensions:
   include: [".py", ".java", ".go", ".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".inl", ".ipp", ".cs", ".rs", ".kt", ".kts", ".rb", ".php", ".sol", ".tf", ".hcl"]
   exclude: [".min.js", ".generated.go", ".pb.go"]
 # A leading "/" matches only that directory at the scan root.
 exclude_dirs: ["node_modules", "vendor", "dist", "/target", "/obj", "/build", ".gradle"]
 max_file_size_kb: 2048   # Maximum file size for discovery (2048 KB / 2 MiB)
 incremental: true

# Restrict agent file access to these directories (all commands).
# When empty, the scan target directory is used as the boundary.
# project_paths: []

output:
 format: table   # "table", "json", "sarif"

tools:
 confirm_commands: true   # Prompt Y/N before running shell commands (default: true)
 confirm_writes: true     # Prompt Y/N before writing/modifying files (default: true)
 # cleanup_candidate_branches: true # Auto-delete temporary candidate branches on completion (default: true)
 # Use --yes flag on find/fix/session resume to skip all confirmations

# Version Control and Automated Testing Guardrails
vcs:
 type: ""               # VCS type: "git", "mercurial", "custom", or "" (auto-detect)
 commands:
   reset: ""            # Shell command to reset codebase (auto-populated for known VCS)
   diff: ""             # Shell command to show changes (auto-populated for known VCS)
   status: ""           # Shell command to list modified files (auto-populated for known VCS)
   stage: ""            # Shell command to stage changes (auto-populated for known VCS)

build:
 command: "npm test"    # Shell command to build/verify changes from the agent

sandbox:
 enabled: true          # Process-level OS sandbox (default: true)
 mounts:
   target_dir: "."
 network:
   profile: "permissive-closed" # Complete network isolation; set to "permissive-open" if build requires internet
security:
 protected_files: []    # Files mounted read-only inside sandbox (e.g. ["~/.ssh/*"])

6. 使用 cm find 发现漏洞。

⏱️ 时长:07:00

在此步骤中,您将运行 cm find . --quick,对 Juice Shop 代码库执行智能体安全扫描。

第 1 步:执行 cm find . --quick

从 CodeMender v0.16.0 开始,cm find <path> 默认设置为深度扫描 (

--deep

),而快速扫描 (

--quick

) 可提供快速的代码库分类。运行 cm find . --quick,对 OWASP Juice Shop 代码库执行快速扫描(预计执行时间:对包含 684 个文件的完整代码库进行分类大约需要 8 分钟):

cm find . --quick -y --sandbox=false --bypass-warning --model gemini-3.8-flash

cm 会在 Gemini Enterprise Agent Platform 上启动扫描会话,分析所有代码库模块中的源代码文件:

⚠️ Sandbox DISABLED and command approval OFF: the agent can run commands on this machine without asking. Code in the scanned repository could steer it. Re-enable the sandbox or command approval (drop --yes, or set tools.confirm_commands: true) unless you trust the repository.
🔍 Discovering files in /home/user/juice-shop...
  Found 684 source files
🚀 Starting FIND session (mode: QUICK)...
  Server: https://aiplatform.googleapis.com
  Session: ChBjMjI4YWY5MzljZjUzNTQ4EAgaAjg1KgRtYWlu
  Operation: ChBjMjI4YWY5MzljZjUzNTQ4EAgaAjg1KgRtYWlu
📂 Scan target: /home/user/juice-shop
🔒 Sandbox roots (agent can only access these directories):
  • /home/user/juice-shop

📡 Waiting for server (https://aiplatform.googleapis.com)...
────────────────────────────────────────────────────────────
2026-10-29T03:01:47Z [INFO]  🔧 [Step 1] list_dir → /home/user/juice-shop
2026-10-29T03:01:56Z [INFO]  🔧 [Step 2] list_dir → .../juice-shop/routes
2026-10-29T03:02:08Z [INFO]  🔧 [Step 3] read_file → .../juice-shop/server.ts
2026-10-29T03:02:47Z [INFO]  🔧 [Step 7] read_file → .../juice-shop/routes/login.ts
2026-10-29T03:02:56Z [INFO]  🔧 [Step 8] read_file → .../juice-shop/routes/search.ts
2026-10-29T03:03:48Z [INFO]  🔧 [Step 13] read_file → .../juice-shop/routes/fileUpload.ts
2026-10-29T03:04:30Z [INFO]  🔧 [Step 16] read_file → .../juice-shop/routes/userProfile.ts
2026-10-29T03:06:11Z [INFO]  🔧 [Step 25] read_file → .../juice-shop/routes/trackOrder.ts
2026-10-29T03:07:57Z [INFO]  🔧 [Step 33] read_file → .../juice-shop/routes/order.ts
2026-10-29T03:09:30Z [INFO]  ✅ Completed 33 tool steps in 7m48s | Tokens: 2.6M in / 8k out / 2.7M total
────────────────────────────────────────────────────────────

🔒 Found 12 vulnerabilities:

ID        SEVERITY    TYPE                                     FILE                             TITLE                                                                                   CONFIDENCE
────────  ────────    ────                                     ────                             ─────                                                                                   ──────────
43aa7446  🔴 CRITICAL  SQL INJECTION                            routes/login.ts                  SQL Injection in User Login Handler Allows Authentication Bypass                        100%
dd83d0a4  🟠 HIGH      SQL INJECTION                            routes/search.ts                 UNION-Based SQL Injection in Product Search Allows Database Exfiltration                100%
4dfe2409  🟠 HIGH      CODE INJECTION                           routes/userProfile.ts            Remote Code Execution via Eval in User Profile Template Handler                         100%
79d490b0  🟠 HIGH      PATH TRAVERSAL                           routes/fileUpload.ts             Path Traversal (Zip Slip) in Zip File Upload Allows Arbitrary File Overwrite            100%
4f2b050c  🟠 HIGH      XML EXTERNAL ENTITY (XXE)                routes/fileUpload.ts             XML External Entity (XXE) Injection in File Upload Route Leaks System Files             100%
1ece0e25  🟠 HIGH      IMPROPER ACCESS CONTROL                  server.ts                        Missing Authorization on Product Update Endpoint Allows Unauthorized Product Tampering  100%
757fd438  🟠 HIGH      CWE-943                                  routes/trackOrder.ts             NoSQL / JavaScript Injection in Order Tracking Allows Database Record Exfiltration      100%
349bac9f  🟡 MEDIUM    SERVER-SIDE REQUEST FORGERY (SSRF)       routes/profileImageUrlUpload.ts  Server-Side Request Forgery (SSRF) in Profile Image URL Upload Route                    100%
be5e1459  🟡 MEDIUM    OPEN REDIRECT                            routes/redirect.ts               Open Redirect via Inadequate Allowlist Substring Match                                  100%
06ecf8a5  🟡 MEDIUM    INSECURE DIRECT OBJECT REFERENCE (IDOR)  routes/basket.ts                 Insecure Direct Object Reference (IDOR) Allows Access to Arbitrary User Baskets         100%
02f6a293  🟡 MEDIUM    PATH TRAVERSAL                           routes/dataErasure.ts            Local File Read via Insecure Template Layout Parameter in Data Erasure Route            100%
95ee59a3  🟡 MEDIUM    CWE-943                                  routes/updateProductReviews.ts   NoSQL Injection in Product Review Update Endpoint Allows Mass Modification              100%

Summary: 1 CRITICAL, 6 HIGH, 5 MEDIUM

Run 'cm report' for detailed analysis, 'cm verify <finding-id>' to validate, or 'cm fix <finding-id>' to generate a patch.
2026-10-29T03:09:30Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T030140Z_ChBjMjI4YWY5MzljZjUzNTQ4EAgaAjg1KgRtYWlu.log

第 2 步:通过 cm report 查看扫描发现结果

运行 cm report -f table,以显示从本地 SQLite 状态数据库中发现的所有安全发现结果:

cm report -f table

输出:

┌──────────┬───────────┬──────┬───┬──────────────────────────────┬────────────────────────────────────────┐
│ID        │Severity   │Status│Fix│File                          │Title                                   │
├──────────┼───────────┼──────┼───┼──────────────────────────────┼────────────────────────────────────────┤
│ 43aa7446 │🔴 CRITICAL│OPEN  │—  │routes/login.ts               │SQL Injection in User Login Handler A...│
│ dd83d0a4 │🟠 HIGH    │OPEN  │—  │routes/search.ts              │UNION-Based SQL Injection in Product ...│
│ 4dfe2409 │🟠 HIGH    │OPEN  │—  │routes/userProfile.ts         │Remote Code Execution via Eval in Use...│
│ 79d490b0 │🟠 HIGH    │OPEN  │—  │routes/fileUpload.ts          │Path Traversal (Zip Slip) in Zip File...│
│ 4f2b050c │🟠 HIGH    │OPEN  │—  │routes/fileUpload.ts          │XML External Entity (XXE) Injection i...│
│ 1ece0e25 │🟠 HIGH    │OPEN  │—  │server.ts                     │Missing Authorization on Product Upda...│
│ 757fd438 │🟠 HIGH    │OPEN  │—  │routes/trackOrder.ts          │NoSQL / JavaScript Injection in Order...│
│ 349bac9f │🟡 MEDIUM  │OPEN  │—  │routes/profileImageUrlUploa...│Server-Side Request Forgery (SSRF) in...│
│ be5e1459 │🟡 MEDIUM  │OPEN  │—  │routes/redirect.ts            │Open Redirect via Inadequate Allowlis...│
│ 06ecf8a5 │🟡 MEDIUM  │OPEN  │—  │routes/basket.ts              │Insecure Direct Object Reference (IDO...│
│ 02f6a293 │🟡 MEDIUM  │OPEN  │—  │routes/dataErasure.ts         │Local File Read via Insecure Template...│
│ 95ee59a3 │🟡 MEDIUM  │OPEN  │—  │routes/updateProductReviews.ts│NoSQL Injection in Product Review Upd...│
└──────────┴───────────┴──────┴───┴──────────────────────────────┴────────────────────────────────────────┘

12 finding(s): 1 CRITICAL, 6 HIGH, 5 MEDIUM · ✅ 0 fixed, 🔴 12 open
📋 Report generated at 2026-10-29 03:10:05 UTC
2026-10-29T03:10:05Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T031005Z_pending.log

第 3 步:了解发现结果生命周期状态和严重级别

CodeMender 通过正式的四状态生命周期跟踪漏洞:

发现结果状态

含义和过渡处理

OPEN

已发现(或导入)漏洞,但尚未验证、修补或忽略。

FIXED

CodeMender 已生成补丁、应用了差异,并验证了 build/测试套件通过且漏洞利用失败。

DISMISSED

由于置信度低、不属于威胁模型或已验证为假正例,因此标记为无效。将未来的提醒静音。

REOPENED

在后续扫描中重新检测到之前FIXED或DISMISSED的缺陷(表示代码回归)。

严重级别分类

CRITICAL:直接来自不可信边界的即时、严重风险(例如远程代码执行、未经身份验证的 SQL 注入)。

HIGH:严重缺陷(例如任意数据库读取、提权),需要特定的用户上下文或连锁条件。

:MEDIUM:中等风险,影响范围受限或需要用户互动(例如,开放重定向、CSRF)。

🔵 LOW:纵深防御卫生缺陷或侦察向量,直接影响极小。

7. 验证漏洞并浏览捕获的验证工件

⏱️ 时长:10:00

CodeMender 的一项关键功能是,每当您运行 cm verify 时,它都会自动生成持久性验证工件。我们来验证一下 routes/login.ts(在本教程中显示为 43aa7446)中的“严重 SQL 注入”发现结果,并查看智能体创建的工件。

第 1 步:执行 cm verify <login-finding-id>

从 cm report 表中找到 routes/login.ts 的发现结果 ID(例如 43aa7446),然后运行 cm verify <finding-id> --sandbox=false --bypass-warning -y(预计执行时间:约 20 分钟,用于运行自主工具步骤、启动后台服务和执行实时 PoC 漏洞利用脚本):

# Replace 43aa7446 with your actual login.ts finding ID
# --sandbox=false turns off only the OS-level sandbox; the path boundary and command policy stay enforced
cm verify 43aa7446 --sandbox=false --bypass-warning -y --model gemini-3.8-flash

输出:

⚠️ Sandbox DISABLED and command approval OFF: the agent can run commands on this machine without asking. Code in the scanned repository could steer it. Re-enable the sandbox or command approval (drop --yes, or set tools.confirm_commands: true) unless you trust the repository.
🔬 Verifying finding: SQL Injection in User Login Handler Allows Authentication Bypass
  ID: 43aa7446-40de-467d-8ca4-8571dca16036
  File: /home/user/juice-shop/routes/login.ts
  Severity: 🔴 CRITICAL
  Type: SQL INJECTION
Resetting workspace at /home/user/juice-shop

🔧 Running: git checkout HEAD -- . && git clean -fd
Removing .cm_project

✅ Reset complete. Ready for vulnerability research.
🚀 Starting VERIFY session...
  Server: https://aiplatform.googleapis.com
  Session: ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu
  Operation: ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu
📂 Scan target: /home/user/juice-shop/routes
🔒 Sandbox boundary (agent can explore within):
  • /home/user/juice-shop

📡 Waiting for verification agent (https://aiplatform.googleapis.com)...
────────────────────────────────────────────────────────────
2026-10-29T03:11:31Z [INFO]  🔧 [Step 1] run_command → mkdir -p /home/user/juice-shop/.exploit
2026-10-29T03:11:42Z [INFO]  🔧 [Step 2] read_file → .../juice-shop/routes/login.ts
2026-10-29T03:12:03Z [INFO]  🔧 [Step 4] read_file → .../juice-shop/package.json
2026-10-29T03:12:14Z [INFO]  🔧 [Step 5] write_to_file → .../juice-shop/.exploit/PLAN.md
2026-10-29T03:19:00Z [INFO]  🔧 [Step 25] run_command → npm run build:server
2026-10-29T03:29:20Z [INFO]  🔧 [Step 61] write_to_file → .../juice-shop/.exploit/info.yaml
2026-10-29T03:29:53Z [INFO]  🔧 [Step 63] write_to_file → .../juice-shop/.exploit/LOG.md
2026-10-29T03:30:17Z [INFO]  🔧 [Step 64] write_to_file → .../juice-shop/.exploit/REPORT.md
2026-10-29T03:30:55Z [INFO]  🔧 [Step 66] run_command → git status --short
2026-10-29T03:31:46Z [INFO]  ✅ Completed 66 tool steps in 20m23s | Tokens: 2.8M in / 7k out / 2.8M total
────────────────────────────────────────────────────────────
2026-10-29T03:31:46Z [INFO]  Artifacts manifest written: /home/user/.codemender/artifacts/ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu/manifest.json (7 artifacts)
📦 Captured 7 agent artifacts in /home/user/.codemender/artifacts/ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu
Pulling artifacts for session ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu
Resetting workspace at /home/user/juice-shop

🔧 Running: git checkout HEAD -- . && git clean -fd
Removing .cm_project
Removing .exploit/LOG.md
Removing .exploit/PLAN.md
Removing .exploit/REPORT.md
Removing .exploit/exploit.sh
Removing .exploit/info.yaml
Removing .exploit/server_runner.js

✅ Reset complete. Ready for vulnerability research.
📥 Copying 7 finding artifact(s) to workspace...
  • /home/user/juice-shop/.exploit/LOG.md
  • /home/user/juice-shop/.exploit/PLAN.md
  • /home/user/juice-shop/.exploit/REPORT.md
  • /home/user/juice-shop/.exploit/exploit.sh
  • /home/user/juice-shop/.exploit/info.yaml
  • /home/user/juice-shop/.exploit/server.log
  • /home/user/juice-shop/.exploit/server_runner.js

🚀 Programmatically running exploit script to confirm: /home/user/juice-shop/.exploit/exploit.sh
EXPLOIT SUCCESSFUL

✅ Exploit execution succeeded. Finding VERIFIED (confidence: 100%)

Run 'cm report' to see updated findings.
2026-10-29T03:31:52Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T031121Z_ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu.log

第 2 步:查看捕获的验证工件

从 CodeMender v0.16.0 开始,验证工件会标准化存储在代码库根目录下的 .exploit/ 中,同时在 ~/.codemender/artifacts/<session-id>/ 中保留一个永久副本。这些是本地工作文件,而不是修复的一部分,因此您需要在下一部分中暂存补丁之前,将它们从 Git 中排除。运行 ls -la .exploit/ 以列出这些服务:

ls -la .exploit/

输出:

total 40
drwxrwxr-x  2 user user 4096 Oct 29 03:31 .
drwxrwxr-x 35 user user 4096 Oct 29 03:31 ..
-rwxr-xr-x  1 user user 3272 Oct 29 03:31 exploit.sh
-rw-r--r--  1 user user  313 Oct 29 03:31 info.yaml
-rw-r--r--  1 user user 2196 Oct 29 03:31 LOG.md
-rw-r--r--  1 user user  771 Oct 29 03:31 PLAN.md
-rw-r--r--  1 user user 6387 Oct 29 03:31 REPORT.md
-rw-rw-r--  1 user user 2438 Oct 29 03:31 server.log
-rw-rw-r--  1 user user  462 Oct 29 03:31 server_runner.js

制品文件

类别

用途

info.yaml

元数据清单

结构化 YAML,用于定义发现结果 UUID、标题、严重程度 (CRITICAL)、置信度 (certain) 和 CWE 标记 (cwe-89)。

PLAN.md

智能体策略

由 CodeMender 推理引擎自主执行的分步验证计划和核对清单。

LOG.md

执行轨迹日志

带有时间戳的审核跟踪记录,记录了每次工具调用、HTTP 请求端点和测试结果。

server_runner.js/server.log

辅助运行程序/服务器日志

智能体创建的用于启动 Juice Shop 进行测试的辅助脚本,以及捕获的服务器输出。

exploit.sh

执行封装容器/独立 PoC

启动目标服务并调用 PoC 客户端的 Shell 脚本封装容器,用于验证 HTTP 200 响应。

REPORT.md

根本原因分析

摘要、逐行漏洞分析、原始 SQL 细分和 Sequelize 参数化建议。

第 3 步:深入了解验证工件要点

智能体在每次运行时都会重新写入这些工件,因此每次运行的确切内容都会有所不同。在 Cloud Shell Editor 中(或使用 cat)打开这些文件,然后查找以下内容:

工件

正确的预期

info.yaml

发现结果的完整 ID、标题、严重级别、置信度和标记(例如 cwe-89)。

PLAN.md

智能体遵循的核对清单,从读取报告的文件到编写重现脚本。

LOG.md

带有时间戳的操作和结果,包括重现脚本每次运行的结果。

exploit.sh

独立重现脚本:它如何启动应用、它定位到哪个端点,以及它如何确定成功(它会输出 EXPLOIT SUCCESSFUL)。

server_runner.js/server.log

智能体为启动 Juice Shop 进行测试而创建的辅助文件,以及该服务器的输出。

REPORT.md

根本原因分析:routes/login.ts 中的漏洞代码行、可被利用的原因以及建议的修复方法(参数化查询)。

8. 使用 cm fix 修复 SQL 注入

⏱️ 时长:10:00

现在,我们已验证 routes/login.ts(示例 ID 43aa7446)中的 SQL 注入发现结果并检查了其工件,接下来让我们执行 cm fix,以应用自动参数化查询补丁。

第 1 步:执行 cm fix <login-finding-id> -y

运行 cm fix <finding-id> --sandbox=false --bypass-warning -y(将 43aa7446 替换为 cm report 中的实际登录发现结果 ID),以合成并应用修复:

# Replace 43aa7446 with your actual login.ts finding ID
cm fix 43aa7446 --sandbox=false --bypass-warning -y --model gemini-3.8-flash

输出:

⚠️ Sandbox DISABLED and command approval OFF: the agent can run commands on this machine without asking. Code in the scanned repository could steer it. Re-enable the sandbox or command approval (drop --yes, or set tools.confirm_commands: true) unless you trust the repository.
🩹 Fixing finding: SQL Injection in User Login Handler Allows Authentication Bypass
  File: /home/user/juice-shop/routes/login.ts
  Severity: CRITICAL
🔒 Sandbox roots (agent can only access these directories):
  • /home/user/juice-shop
Found latest VERIFY session ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu for finding 43aa7446-40de-467d-8ca4-8571dca16036
Pulling artifacts for session ChBkZTRhMWU3YTI4MjU5ZDY0EAgaAmU4KgRtYWlu
Resetting workspace at /home/user/juice-shop

🔧 Running: git checkout HEAD -- . && git clean -fd
Removing .cm_project
Removing .exploit/LOG.md
Removing .exploit/PLAN.md
Removing .exploit/REPORT.md
Removing .exploit/exploit.sh
Removing .exploit/info.yaml
Removing .exploit/server_runner.js

✅ Reset complete. Ready for vulnerability research.
📥 Copying 7 finding artifact(s) to workspace...
  • /home/user/juice-shop/.exploit/LOG.md
  • /home/user/juice-shop/.exploit/PLAN.md
  • /home/user/juice-shop/.exploit/REPORT.md
  • /home/user/juice-shop/.exploit/exploit.sh
  • /home/user/juice-shop/.exploit/info.yaml
  • /home/user/juice-shop/.exploit/server.log
  • /home/user/juice-shop/.exploit/server_runner.js
  Session: ChA0YjllNzFkMTgyM2JmZDQ0EAgaAjdiKgRtYWlu
  Operation: ChA0YjllNzFkMTgyM2JmZDQ0EAgaAjdiKgRtYWlu

📡 Waiting for fix agent (https://aiplatform.googleapis.com)...
────────────────────────────────────────────────────────────
2026-10-29T03:41:30Z [INFO]  🔧 [Step 4] read_file → .../juice-shop/routes/login.ts
2026-10-29T03:41:58Z [INFO]  🔧 [Step 6] run_command → npm run test:server
2026-10-29T03:43:11Z [INFO]  🔧 [Step 9] grep_search → pattern="sequelize\\.query" path=.../juice-shop/routes
2026-10-29T03:43:54Z [INFO]  🔧 [Step 12] read_file → .../juice-shop/routes/vulnCodeSnippet.ts
2026-10-29T03:44:41Z [INFO]  🔧 [Step 13] read_file → .../juice-shop/routes/vulnCodeFixes.ts
2026-10-29T03:53:14Z [INFO]  🔧 [Step 31] search_and_replace → .../juice-shop/routes/login.ts
2026-10-29T03:53:52Z [INFO]  🔧 [Step 33] run_command → npm run build:server
2026-10-29T03:55:23Z [INFO]  🔧 [Step 37] run_command → npm run test:server
2026-10-29T03:55:49Z [INFO]  🔧 [Step 38] run_command → git diff
2026-10-29T03:57:18Z [INFO]  ✅ Completed 43 tool steps in 16m54s | Tokens: 1.6M in / 4k out / 1.6M total
────────────────────────────────────────────────────────────

✨ Patch generated successfully!

diff --git a/routes/login.ts b/routes/login.ts
index fb9fce3..57f3afe 100644
--- a/routes/login.ts
+++ b/routes/login.ts
@@ -31,7 +31,14 @@ export function login () {

  return (req: Request, res: Response, next: NextFunction) => {
    verifyPreLoginChallenges(req) // vuln-code-snippet hide-line
-    models.sequelize.query(`SELECT * FROM Users WHERE email = '${req.body.email || ''}' AND password = '${security.hash(req.body.password || '')}' AND deletedAt IS NULL`, { model: UserModel, plain: true }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge
+    models.sequelize.query('SELECT * FROM Users WHERE email = :email AND password = :password AND deletedAt IS NULL', {
+      replacements: {
+        email: typeof req.body?.email === 'string' ? req.body.email : '',
+        password: security.hash(typeof req.body?.password === 'string' ? req.body.password : '')
+      },
+      model: UserModel,
+      plain: true
+    }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge
      .then((authenticatedUser) => { // vuln-code-snippet neutral-line loginAdminChallenge loginBenderChallenge loginJimChallenge
        const user = utils.queryResultToJson(authenticatedUser)
        if (user.data?.id && user.data.totpSecret !== '') {

────────────────────────────────────────────────────────────
2026-10-29T03:57:18Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T034021Z_ChA0YjllNzFkMTgyM2JmZDQ0EAgaAjdiKgRtYWlu.log

第 2 步:使用 cm vcs 检查 VCS 状态和差异

运行 cm vcs status 和 cm vcs diff 以查看修改后的工作区文件:

cm vcs status
cm vcs diff

输出:

📂 CodeMender VCS Status
──────────────────────────────────────────────────
  Directory: /home/user/juice-shop
  Command:   git status --short
──────────────────────────────────────────────────

M routes/login.ts
?? .cm_project
?? .exploit/
2026-10-29T03:59:47Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T035947Z_pending.log

这两个未跟踪的条目是 CodeMender 的本地文件,不属于修复内容:.exploit/ 包含来自 cm verify 的验证工件,.cm_project 标记 CodeMender 的项目根目录。在下一步中,您将避免将它们包含在提交中。

和 cm vcs diff:

🔍 Running diff in /home/user/juice-shop: git diff
diff --git a/routes/login.ts b/routes/login.ts
index fb9fce3..57f3afe 100644
--- a/routes/login.ts
+++ b/routes/login.ts
@@ -31,7 +31,14 @@ export function login () {

  return (req: Request, res: Response, next: NextFunction) => {
    verifyPreLoginChallenges(req) // vuln-code-snippet hide-line
-    models.sequelize.query(`SELECT * FROM Users WHERE email = '${req.body.email || ''}' AND password = '${security.hash(req.body.password || '')}' AND deletedAt IS NULL`, { model: UserModel, plain: true }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge
+    models.sequelize.query('SELECT * FROM Users WHERE email = :email AND password = :password AND deletedAt IS NULL', {
+      replacements: {
+        email: typeof req.body?.email === 'string' ? req.body.email : '',
+        password: security.hash(typeof req.body?.password === 'string' ? req.body.password : '')
+      },
+      model: UserModel,
+      plain: true
+    }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge
      .then((authenticatedUser) => { // vuln-code-snippet neutral-line loginAdminChallenge loginBenderChallenge loginJimChallenge
        const user = utils.queryResultToJson(authenticatedUser)
        if (user.data?.id && user.data.totpSecret !== '') {

第 3 步:使用 cm vcs stage 暂存经过验证的补丁

在您查看统一差异并确认修复措施符合您的质量和安全标准后,请暂存补丁以供提交。由于 cm vcs stage 会运行 git add -A,因此它会暂存工作树中的每项更改,包括第 2 步中未跟踪的 .exploit/ 和 .cm_project 条目。首先,将它们添加到 .git/info/exclude(Git 绝不会提交的仅限本地的忽略文件),以便仅暂存补丁:

# Keep CodeMender's local files out of Git (local-only; not committed)
printf '.exploit/\n.cm_project\n' >> .git/info/exclude

然后使用 cm vcs stage 暂存更改:

cm vcs stage

输出:

📦 CodeMender VCS Stage
──────────────────────────────────────────────────
  Directory: /home/user/juice-shop
  Command:   git add -A
──────────────────────────────────────────────────

2026-10-29T04:00:06Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T040006Z_pending.log
✅ Changes staged successfully.

验证 Git 中是否仅暂存了补丁:

cm vcs status

输出:

📂 CodeMender VCS Status
──────────────────────────────────────────────────
  Directory: /home/user/juice-shop
  Command:   git status --short
──────────────────────────────────────────────────

M  routes/login.ts

如果您在更新 .git/info/exclude 之前运行了 cm vcs stage,请使用 git restore --staged .exploit .cm_project 取消暂存 CodeMender 文件。这些文件仍会保留在磁盘上,只是从暂存区中移除。

第 4 步:提交补丁并清除验证制品

在修复下一个发现结果之前,请先提交暂存的补丁:每次运行 cm fix 和 cm verify 时,系统都会先重置工作区 (git checkout HEAD -- . && git clean -fd),这会舍弃未提交的更改。然后删除本地 .exploit/ 文件夹,以便下一个修复操作从干净的工作区开始。由于 .exploit/ 现已被忽略,git clean -fd 不会再为您移除它。工件的永久副本仍保留在 ~/.codemender/artifacts/<session-id>/ 中。

git commit -m "fix: use parameterized query in login route"
rm -rf .exploit/

如果 Git 要求您提供身份信息,请在代码库中运行 git config user.name "Your Name" 和 git config user.email "you@example.com",然后再次提交。

9. 验证补丁、管理会话和导出报告 (cm report)

⏱️ 时长:08:00

应用 AI 生成的安全修复程序后,必须使用 cm report 管理活跃会话、检查令牌使用情况统计信息并生成企业安全合规报告。

第 1 步:管理有状态会话 (cm session list / resume / cancel)

CodeMender 会将每项扫描、验证和修复任务作为有状态会话跟踪到其本地 SQLite 数据库 (~/.codemender/state.db) 中。运行 cm session list 即可检查会话:

cm session list

输出:

SESSION_ID  TYPE    STATUS       TARGET                          CREATED              RESUMABLE
──────────  ────    ──────       ──────                          ───────              ─────────
ChA0Yjll    FIX     ✅ COMPLETED  ...40de-467d-8ca4-8571dca16036  2026-10-29T03:40:21  —
ChBkZTRh    VERIFY  ✅ COMPLETED  ...40de-467d-8ca4-8571dca16036  2026-10-29T03:11:21  —
ChBjMjI4    FIND    ✅ COMPLETED  /home/user/juice-shop           2026-10-29T03:01:40  —

3 session(s) total
2026-10-22T02:24:43Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261022T022443Z_pending.log

第 2 步:运行 cm report 以验证已修复的发现结果

运行 cm report -f table 以显示更新后的发现结果状态(请注意,已修复的发现结果现在会在 Fix 列中显示 FIXED 和 ✅ applied):

cm report -f table

输出:

┌──────────┬───────────┬──────┬──────────┬──────────────────────────────┬────────────────────────────────────────┐
│ID        │Severity   │Status│Fix       │File                          │Title                                   │
├──────────┼───────────┼──────┼──────────┼──────────────────────────────┼────────────────────────────────────────┤
│ 43aa7446 │🔴 CRITICAL│FIXED │✅ applied│routes/login.ts               │SQL Injection in User Login Handler A...│
│ dd83d0a4 │🟠 HIGH    │OPEN  │—         │routes/search.ts              │UNION-Based SQL Injection in Product ...│
│ 4dfe2409 │🟠 HIGH    │OPEN  │—         │routes/userProfile.ts         │Remote Code Execution via Eval in Use...│
│ 79d490b0 │🟠 HIGH    │OPEN  │—         │routes/fileUpload.ts          │Path Traversal (Zip Slip) in Zip File...│
│ 4f2b050c │🟠 HIGH    │OPEN  │—         │routes/fileUpload.ts          │XML External Entity (XXE) Injection i...│
│ 1ece0e25 │🟠 HIGH    │OPEN  │—         │server.ts                     │Missing Authorization on Product Upda...│
│ 757fd438 │🟠 HIGH    │OPEN  │—         │routes/trackOrder.ts          │NoSQL / JavaScript Injection in Order...│
│ 349bac9f │🟡 MEDIUM  │OPEN  │—         │routes/profileImageUrlUploa...│Server-Side Request Forgery (SSRF) in...│
│ be5e1459 │🟡 MEDIUM  │OPEN  │—         │routes/redirect.ts            │Open Redirect via Inadequate Allowlis...│
│ 06ecf8a5 │🟡 MEDIUM  │OPEN  │—         │routes/basket.ts              │Insecure Direct Object Reference (IDO...│
│ 02f6a293 │🟡 MEDIUM  │OPEN  │—         │routes/dataErasure.ts         │Local File Read via Insecure Template...│
│ 95ee59a3 │🟡 MEDIUM  │OPEN  │—         │routes/updateProductReviews.ts│NoSQL Injection in Product Review Upd...│
└──────────┴───────────┴──────┴──────────┴──────────────────────────────┴────────────────────────────────────────┘

12 finding(s): 1 CRITICAL, 6 HIGH, 5 MEDIUM · ✅ 1 fixed, 🔴 11 open
📋 Report generated at 2026-10-29 04:01:10 UTC
2026-10-29T04:01:10Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261029T040110Z_pending.log

第 3 步:使用 cm stats 检查 token 用量

运行 cm stats,检查各种扫描模式(cm find --quick、cm verify 和 cm fix)下的本地 token 消耗情况:

cm stats

输出:

COMMAND          REQUESTS  POLLS  INPUT   OUTPUT  CACHED  THOUGHT  TOOL_CALLS  TOTAL   CACHE_HIT%  THINK_RATIO%  DURATION
───────          ────────  ─────  ─────   ──────  ──────  ───────  ──────────  ─────   ──────────  ────────────  ────────
total            3         186    10.7M   23.1k   9.9M    55.5k    0           10.8M   91.8%       70.7%         35m 54s
cm find --quick  1         33     2.0M    9.4k    1.8M    15.2k    0           2.1M    90.6%       61.8%         05m 44s
cm fix           1         33     870.9k  908     678.6k  20.3k    0           892.2k  77.9%       95.7%         04m 40s
cm verify        1         120    7.8M    12.7k   7.3M    20.0k    0           7.9M    93.6%       61.1%         25m 31s

3 turn(s) across 3 command type(s) in the last 7 days
2026-10-22T02:24:46Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261022T022446Z_pending.log

第 4 步:生成并预览交互式 HTML 报告 (cm report -f html)

将扫描结果和已应用的补丁导出为独立的交互式 HTML 信息中心:

cm report -f html
cp ~/.codemender/reports/report.html ./report.html

如需在 Google Cloud Shell 中查看 report.html,请执行以下操作:

在 Cloud Shell 终端中启动本地预览 Web 服务器:

python3 -m http.server 8080

在 Cloud Shell 的右上角工具栏中,依次点击网页预览按钮(带有眼睛/屏幕的图标)➔ 在端口 8080 上预览,即可在浏览器中查看交互式合规性信息中心。

(替代方法)在 Cloud Shell 编辑器文件资源管理器中,右键点击 report.html,然后点击下载,即可在本地浏览器中查看该文件。

第 5 步:生成的互动式 HTML 报告的主要功能

以下是生成的互动式 HTML 报告 (report.html) 的关键组成部分:

CodeMender 安全合规信息中心概览

1. 高管指标标题和安全状况卡片

CodeMender Executive Metrics Header and Posture Cards标头元数据:显示目标代码库详细信息 (OWASP Juice Shop)、扫描的源文件总数 (684 files) 以及 UTC 生成时间戳。

指标卡片网格:提供发现结果总数、严重程度分布(CRITICAL、HIGH、MEDIUM、LOW)和已修复漏洞总数 (FIXED) 的即时概览。

2. 互动式发现结果摘要表

CodeMender 发现结果摘要表漏洞矩阵:显示一个可过滤的表格,其中包含ID、Severity、Status(OPEN 与 FIXED)、CWE Type、File Location、Vulnerability Title 和 Confidence Score。

3. 深入的根本原因分析和易受攻击的源代码段

CodeMender 根本原因分析和代码段可折叠分析 (RCA):点击任何发现结果行,即可展开由 Gemini 安全推理模型合成的详细根本原因分析。

易受攻击的源代码段:显示易受攻击的接收器周围的确切行号和语法突出显示的源代码。

4. 合成的 AI 修复补丁差异

CodeMender 合成修复补丁差异统一差异视图:对于已修复的漏洞 (FIXED),CodeMender 会呈现一个统一差异块,其中用绿色 (+) 突出显示已应用的应用代码添加内容,用红色 (-) 突出显示已移除的易受攻击代码。

第 6 步:(可选)导入第三方 SAST 发现结果 (cm report import)

CodeMender 的能力并不局限于其自身扫描器发现的缺陷。团队可以使用标准化的 JSON 架构或交互式向导导入外部 SAST 结果(例如来自 Semgrep、Snyk、SonarQube 或 Fortify 的结果),让 CodeMender 能够立即验证并合成修复方案:

# Create a sample third-party findings JSON file
cat << 'EOF' > ./findings.json
[
 {
   "file_path": "routes/basket.ts",
   "line": 18,
   "title": "SQL Injection in Basket Handler",
   "message": "Raw basket ID concatenated in query",
   "severity": "HIGH",
   "vuln_type": "CWE-89"
 }
]
EOF

# Ingest findings into CodeMender state database
cm report import --file ./findings.json

输出:

Successfully imported 1 findings.
2026-10-22T02:27:10Z [INFO]  📄 Session log: /home/user/.codemender/logs/20261022T022710Z_pending.log

10. 清理资源

⏱️ 时长:01:00

为避免在 Google Cloud Shell 环境中产生不必要的磁盘用量,并清理临时研讨会资源,请按照以下清理步骤操作。

第 1 步:清除 CodeMender 本地缓存并移除代码库

CodeMender 提供内置的 cm clean 命令,用于清除本地发现结果数据库 (~/.codemender/state.db)、HTML 报告和源代码备份文件。在 Cloud Shell 中执行以下命令:

# Purge local SQLite findings cache, HTML reports, and backup files
cm clean

# Remove cloned repository
cd ~
rm -rf ~/juice-shop

第 2 步:(可选)停用 Google Cloud API

如果您不打算在此项目中使用 CodeMender 或 Agent Platform API 进行进一步开发,可以停用这些服务 API:

gcloud services disable \
 aiplatform.googleapis.com \
 cloudresourcemanager.googleapis.com \
 --project=${PROJECT_ID}

11. 恭喜

⏱️ 时长:02:00

恭喜!您已成功使用 Google Cloud 的 Gemini Enterprise Agent Platform 上的 CodeMender,将 OWASP Juice Shop 从一个故意留有漏洞的应用转变为一个经过强化的安全代码库。

所学内容

自主闭环修复:CodeMender 摆脱了被动静态提醒的干扰,执行完整的自主安全生命周期,涵盖从代码库发现 (cm find) 到沙盒漏洞利用验证 (cm verify) 以及回归测试补丁合成 (cm fix) 的全过程。

基于证据的漏洞利用证明:通过捕获有形的验证工件(PLAN.md、LOG.md、exploit.sh、REPORT.md),CodeMender 可在编写任何代码之前消除假正例并证明实际可利用性。

基于上下文的惯用修复:Gemini 推理智能体不会应用通用的文本替换,而是分析应用架构、数据模型和 ORM,以生成干净、可维护的补丁(例如参数化 Sequelize 查询),从而保留现有业务逻辑。

内置安全和测试防护机制:在暂存更改之前,系统会在隔离的工作区沙盒中,根据项目测试套件 (npm test) 和类型检查器 (tsc) 自动验证每个建议的修复。

开发者思维方式转变

传统手动 SAST 工作流

使用 CodeMender (cm) 进行自主修复

警报疲劳:花费数小时对误报率高的嘈杂报告进行分类。

Agentic Code Discovery (cm find .):由 Gemini 模型提供支持的深度、上下文感知型代码库扫描。

手动 PoC 验证:制作自定义 curl 载荷和攻击脚本,以确认漏洞。

自动漏洞利用证明 (cm verify ):自动生成可执行的验证计划、日志和 shell 脚本。

高风险的手动重构:手动修补复杂的数据库查询,这通常会引入语法或运行时错误。

惯用补丁合成 (cm fix ):根据现有 ORM 和框架标准量身定制的情境感知差异生成。

生产环境回归风险:安全补丁经常会破坏下游业务逻辑或测试。

自动化测试护栏:针对本地测试套件和隔离进程沙盒进行持续验证。

手动合规性汇编:手动将发现结果汇总到静态文档中,以供审核。

标准化遥测和 SARIF (cm report -f sarif):即时导出 OASIS SARIF v2.1.0、HTML 信息中心和 token 分析。

后续步骤

🚀 继续 CodeMender 三部曲:

第 2 部分:使用 CodeMender 保护 CI/CD 流水线 - 在 GitHub Actions 中自动执行持续无头扫描、SARIF 信息中心集成和自修复拉取请求。

第 3 部分:使用 Antigravity 和 CodeMender 实现安全的 Vibe-Coding - 将生成式 AI 开发与自主安全助理相结合。

📖 探索文档:

Google Cloud 上的 CodeMender 文档

Google Cloud 安全解决方案

💡 应用到您自己的项目:

在您自己的 Node.js、Python、Go、Java、Rust 或 C/C++ 代码库中运行 cm find . 和 cm fix!