跳到主要内容
🚀 新功能:Snyk Mission Control 与持续 AI 集成新的Snyk Mission Control 集成支持持续 AI——AI 代理自主检测、分析和修复漏洞。当 Snyk 检测到问题时,您的代理会自动生成修复方案,创建 PR,并验证解决方案,无需人工干预。Mission Control 优势:
  • 一键 OAuth - 无需令牌,无需配置文件,即连即用
  • 集中式工作流 - 从一个仪表板管理所有安全任务和自动化
  • Webhook 触发器 - 自动响应新发现的漏洞
  • 指标和干预率 - 跟踪代理在无人协助下成功修复问题的频率
这代表了持续 AI 的第 2 级:AI 自主处理日常安全工作,开发人员专注于复杂问题。正如我们的持续 AI 指南中所述,这降低了干预率并加速了安全开发。入门:使用本手册了解基础知识,然后启用 Mission Control 以在您的组织中部署自主安全代理。

您将构建什么

一个自动化安全扫描系统,使用 Continue 的 AI 代理和 Snyk MCP 来识别代码、依赖项、基础设施和容器中的漏洞——所有这些都通过简单的自然语言提示完成

演示视频

先决条件

开始前,请确保您已具备 对于所有选项,首先
1

安装 Continue CLI

curl -fsSL https://raw.githubusercontent.com/continuedev/continue/main/extensions/cli/scripts/install.sh | bash
2

将您的项目添加到 Snyk

  1. snyk.io 注册 Snyk 账户
  2. 通过导入您的代码仓库(Git 提供商或手动上传)在 Snyk 中创建一个新项目
  3. 在本地安装并认证 Snyk CLI
    npm install -g snyk
    snyk auth
    
    这将打开您的浏览器以使用您的 Snyk 账户进行认证。
重要提示:Snyk MCP 要求 Snyk CLI 在本地进行认证。在使用 Continue 代理与 Snyk MCP 之前,运行 snyk auth 进行认证。
要在无头模式下使用代理,您需要一个 Continue API 密钥

Snyk 持续 AI 工作流程选项

🚀 最快的成功之路

跳过手动设置,使用我们预构建的 Snyk 持续 AI 代理,其中包含 Snyk MCP 和优化的安全扫描工作流,以获得更一致的结果。
在确保您满足上述先决条件后,您有两种入门方法
要使用预构建代理,您需要满足以下任一条件:
  • Continue CLI 专业版计划,附带模型插件,或
  • 您自己的 API 密钥已添加到 Continue Mission Control 密钥(与手动设置相同)
代理将自动检测并使用您的配置以及预配置的 Snyk MCP 进行安全扫描操作。

安全扫描方案

现在您可以使用自然语言提示运行全面的安全扫描。Continue 代理会自动调用适当的 Snyk MCP 工具。
您可以将提示添加到代理的配置中,以便将来轻松访问。访问 Continue Mission Control 中的代理,点击编辑,并在提示部分下添加提示。
在哪里运行这些工作流
  • IDE 扩展:在 VS Code、JetBrains 或其他受支持的 IDE 中使用 Continue
  • 终端(TUI 模式):运行 cn 进入交互模式,然后输入您的提示
  • CLI(无头模式):使用 cn -p "您的提示" --auto 进行无头命令
首先在计划模式下测试:在运行可能进行更改的安全扫描之前,在计划模式下测试您的提示(请参阅计划模式指南;在 TUI/IDE 中按 Shift+Tab 切换模式)。这会显示代理将做什么而不会执行它。例如:"运行 Snyk Code 扫描并修复前 3 个问题"

代码漏洞扫描 (SAST)

静态应用安全测试

扫描您的源代码以查找安全漏洞和代码质量问题。TUI 模式提示:
Run a Snyk Code scan on this repo with severity threshold medium.
Summarize issues with file:line. Propose minimal diffs for the top 3
and rerun to verify.
无头模式提示
cn -p "Run a Snyk Code scan on this repo with severity threshold medium. Summarize issues with file:line. Propose minimal diffs for the top 3 and rerun to verify." --auto

依赖项扫描 (SCA)

软件组成分析

检查开源依赖项中是否存在已知漏洞。TUI 模式提示:
Run Snyk Open Source on this repo (include dev deps).
Summarize vulnerable paths and propose a minimal-risk upgrade plan.
Re-test after the plan (dry run).
无头模式提示
cn -p "Run Snyk Open Source on this repo (include dev deps). Summarize vulnerable paths and propose a minimal-risk upgrade plan. Re-test after the plan (dry run)." --auto

基础设施即代码 (IaC)

IaC 安全

扫描 Terraform、CloudFormation 和 Kubernetes 配置中的错误配置。TUI 模式提示:
Scan ./infra with Snyk IaC. Report high/critical misconfigs
with exact files/lines. Provide code changes and re-scan to confirm.
无头模式提示
cn -p "Scan ./infra with Snyk IaC. Report high/critical misconfigs with exact files/lines. Provide code changes and re-scan to confirm." --auto

容器扫描

容器安全

分析 Docker 镜像中基础镜像和软件包中的漏洞。TUI 模式提示:
Scan image my-api:latest. Exclude base image vulns.
Print dependency tree. Recommend a safer base image or upgrades.
Re-test after the change (dry run).
无头模式提示
cn -p "Scan image my-api:latest. Exclude base image vulns. Print dependency tree. Recommend a safer base image or upgrades. Re-test after the change (dry run)." --auto

拉取请求扫描

仅限更改的文件

将扫描重点放在修改过的文件上,以便在合并之前发现问题。TUI 模式提示:
Scan only files changed since origin/main with Snyk Code.
Block if new high issues would be introduced. Show deltas.
无头模式提示
cn -p "Scan only files changed since origin/main with Snyk Code. Block if new high issues would be introduced. Show deltas." --auto

安全学习

Snyk Learn 集成

根据已识别的漏洞 (CWE) 获取安全教育资源。TUI 模式提示:
Open Snyk Learn lessons related to the top CWE(s) from this scan.
无头模式提示
cn -p "Open Snyk Learn lessons related to the top CWE(s) from this scan." --auto

使用 GitHub Actions 实现持续安全

此示例演示了持续 AI 工作流,其中安全扫描在拉取请求上自动运行,生成 AI 驱动的缓解建议,并将其作为 PR 评论发布。
关于 —auto 标志--auto 标志允许工具在无需手动确认的情况下持续运行。这对于无头模式至关重要,在这种模式下,代理需要自动执行多个工具来完成安全扫描、漏洞分析和修复验证等任务。

添加 GitHub Secrets

导航到 Repository Settings → Secrets and variables → Actions 并添加

创建工作流文件

在您的仓库中创建 .github/workflows/snyk-security.yml
name: Snyk Security Scanning

on:
  pull_request:
    branches: [main]

jobs:
  security-scan:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Fetch all history for git diff

      - name: Get Changed Files
        id: changed-files
        run: |
          echo "📝 Getting changed files since main branch..."
          CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | tr '\n' ' ')
          echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
          echo "Changed files: $CHANGED_FILES"

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install Snyk CLI
        run: |
          npm install -g snyk
          echo "✅ Snyk CLI installed"

      - name: Install Continue CLI
        run: |
          npm install -g @continuedev/cli
          echo "✅ Continue CLI installed"

      - name: Validate Secrets
        run: |
          if [ -z "${{ secrets.SNYK_TOKEN }}" ]; then
            echo "❌ Error: SNYK_TOKEN secret is not set"
            exit 1
          fi
          if [ -z "${{ secrets.CONTINUE_API_KEY }}" ]; then
            echo "⚠️ Warning: CONTINUE_API_KEY not set - AI mitigation suggestions will be skipped"
          fi
          echo "✅ Required secrets validated"

      - name: Authenticate Snyk
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        run: |
          snyk auth "$SNYK_TOKEN"
          echo "✅ Snyk authenticated"

      - name: Run Security Scans
        id: security-scan
        continue-on-error: true
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
          CHANGED_FILES: ${{ steps.changed-files.outputs.changed_files }}
        run: |
          SCAN_FAILED=0

          if [ -n "$CHANGED_FILES" ]; then
            echo "🔍 Running targeted scan on changed files..."
            echo "Changed files: $CHANGED_FILES"
            FILE_ARGS=""
            for file in $CHANGED_FILES; do
              if [[ "$file" =~ \.(js|jsx|ts|tsx|py|java|go|rb)$ ]]; then
                FILE_ARGS="$FILE_ARGS --file=$file"
              fi
            done

            if [ -n "$FILE_ARGS" ]; then
              echo "🔍 Running Snyk Code scan on changed files..."
              snyk code test $FILE_ARGS --severity-threshold=high --json > snyk-code-results.json || {
                echo "❌ Snyk Code found high severity issues in changed files"
                SCAN_FAILED=1
              }
            else
              echo "⚠️ No scannable code files changed, skipping Snyk Code scan"
              echo '{"runs": [{"results": []}]}' > snyk-code-results.json
            fi
          else
            echo "⚠️ No changed files detected, creating empty results"
            echo '{"runs": [{"results": []}]}' > snyk-code-results.json
          fi

          echo "📦 Checking dependencies..."
          snyk test --severity-threshold=high --json > snyk-oss-results.json || {
            echo "❌ Snyk Open Source found high severity issues"
            SCAN_FAILED=1
          }

          if [ $SCAN_FAILED -eq 1 ]; then
            echo "scan_status=failed" >> $GITHUB_OUTPUT
            echo "⚠️ Scans completed with issues - continuing to generate mitigation suggestions"
          else
            echo "scan_status=passed" >> $GITHUB_OUTPUT
            echo "✅ All security scans passed"
          fi

      - name: Generate AI Mitigation Suggestions
        if: always() && steps.security-scan.outputs.scan_status == 'failed'
        continue-on-error: true
        env:
          CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        run: |
          echo "🤖 Generating AI-powered mitigation suggestions..."

          # Create a summary of findings for Continue CLI
          FINDINGS_SUMMARY=$(cat snyk-code-results.json snyk-oss-results.json | jq -r '
            if .runs then
              .runs[0].results[] | "Code Issue: \(.message.text) in \(.locations[0].physicalLocation.artifactLocation.uri) (Severity: \(.level))"
            elif .vulnerabilities then
              .vulnerabilities[] | "Dependency Issue: \(.title) in \(.packageName)@\(.version) (Severity: \(.severity))"
            else
              empty
            end
          ' | head -20)

          if [ -n "$FINDINGS_SUMMARY" ]; then
            echo "📋 Security findings to analyze:"
            echo "$FINDINGS_SUMMARY"
            echo ""

            # Use Continue CLI to generate mitigation suggestions
            PROMPT="Analyze these Snyk security findings and provide specific, actionable mitigation steps for each issue. Focus on: 1) Root cause, 2) Immediate fix, 3) Long-term prevention. Findings: $FINDINGS_SUMMARY. Provide clear, prioritized recommendations."

            cn --agent continuedev/snyk-continuous-ai-agent -p "$PROMPT" --auto > mitigation-suggestions.md || {
              echo "⚠️ Warning: Could not generate AI suggestions"
              exit 0
            }

            if [ -f mitigation-suggestions.md ]; then
              echo "✅ AI mitigation suggestions generated"
              echo ""
              echo "--- Mitigation Suggestions ---"
              cat mitigation-suggestions.md
            fi
          else
            echo "⚠️ No findings to analyze"
          fi

      - name: Post Mitigation Summary to PR
        if: steps.security-scan.outputs.scan_status == 'failed' && hashFiles('mitigation-suggestions.md') != ''
        continue-on-error: true
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          if [ -f mitigation-suggestions.md ]; then
            echo "💬 Posting mitigation summary to PR..."

            # Create PR comment with mitigation suggestions
            cat > pr-comment.md <<'EOF'
          ## 🛡️ Snyk Mitigation Summary

          Snyk has identified security issues in this PR. Here are AI-generated mitigation recommendations:

          EOF

            cat mitigation-suggestions.md >> pr-comment.md

            cat >> pr-comment.md <<EOF

          ---
          **Scan Details:**
          - 📊 Full report available in workflow artifacts
          - 🔍 Review the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for complete details
          - 🤖 Generated with Continue CLI + Snyk

          _This is an automated security analysis. Please review and address the findings before merging._
          EOF

            gh pr comment ${{ github.event.pull_request.number }} --body-file pr-comment.md

            echo "✅ Mitigation summary posted to PR"
          else
            echo "⚠️ No mitigation suggestions file found"
          fi

      - name: Generate Security Report
        if: always()
        continue-on-error: true
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        run: |
          echo "📊 Generating security report..."
          {
            echo "# Security Scan Report"
            echo ""
            echo "**Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
            echo "**Branch:** ${{ github.ref_name }}"
            echo "**Commit:** ${{ github.sha }}"
            echo "**Status:** ${{ steps.security-scan.outputs.scan_status }}"
            echo ""

            echo "## Snyk Code Scan Results"
            if [ -f snyk-code-results.json ]; then
              jq -r '.runs[0].results[] | "- **\(.level | ascii_upcase)**: \(.message.text) in \(.locations[0].physicalLocation.artifactLocation.uri)"' snyk-code-results.json || echo "No code issues found"
            else
              echo "No scan results available"
            fi
            echo ""

            echo "## Snyk Open Source Scan Results"
            if [ -f snyk-oss-results.json ]; then
              jq -r '.vulnerabilities[] | "- **\(.severity | ascii_upcase)**: \(.title) (\(.packageName)@\(.version))"' snyk-oss-results.json || echo "No dependency issues found"
            else
              echo "No scan results available"
            fi
            echo ""

            if [ -f mitigation-suggestions.md ]; then
              echo "## AI-Powered Mitigation Suggestions"
              echo ""
              cat mitigation-suggestions.md
            fi
          } > scan-results.md

          if [ -f scan-results.md ]; then
            echo "✅ Security report generated successfully"
            cat scan-results.md
          else
            echo "⚠️ Warning: scan-results.md was not created"
          fi

      - name: Upload Security Report
        if: always()
        continue-on-error: true
        uses: actions/upload-artifact@v4
        with:
          name: security-scan-results
          path: |
            scan-results.md
            snyk-code-results.json
            snyk-oss-results.json
            mitigation-suggestions.md
          if-no-files-found: warn

      - name: Fail if Security Issues Found
        if: steps.security-scan.outputs.scan_status == 'failed'
        run: |
          echo "❌ Security scan failed - high severity issues found"
          echo "📋 Review the security report artifact for details and mitigation suggestions"
          exit 1
关于 SNYK_TOKEN:工作流以两种方式使用 SNYK_TOKEN
  1. 直接 Snyk CLI 认证 - 认证 Snyk CLI 以运行扫描
  2. Continue CLI 访问 - 当 Continue 生成 AI 缓解建议时,可作为环境变量使用
cn 代理在 Snyk MCP 操作需要时会自动使用 SNYK_TOKEN。
此工作流演示了几个高级功能
  • 更改文件检测:仅扫描 PR 中修改的文件
  • AI 缓解:使用 Continue CLI 生成可操作的缓解步骤
  • PR 评论:自动将缓解建议发布为 PR 评论
  • 全面报告:生成带有工件的详细安全报告

安全防护

使用 Continue 的规则系统实施自动化安全策略。请参阅规则深入探讨以获取编写技巧。
即将推出:这些安全防护提示将作为预配置规则在 Continue Mission Control 上提供,以便于安装。

预提交扫描

"Always run Snyk Code before committing newly
generated code; refuse to proceed if high
issues remain."

依赖安全

"When adding/updating a dependency, run Snyk Open Source, choose the
lowest-risk upgrade, and re-test."

容器加固

"Before building containers, scan base images and recommend
security-hardened alternatives."

IaC 合规性

"Scan all Terraform changes for compliance
violations before applying infrastructure."
从 Mission Control 启用安全原生规则,以自动将这些防护应用于所有代码生成和修改。

故障排除

认证问题

"Check Snyk auth status and current org. If not authenticated,
help me authenticate. Then run a quick Code scan on ./
with severity medium and print one example issue."

修复验证

"Propose minimal diffs only in affected files,
then rerun the same Snyk scan to confirm resolution."

连接问题

验证步骤: - Snyk MCP 通过Continue Hub 安装 - 安全原生规则已启用 - 认证成功完成 - 项目文件夹已被信任

你已构建完成

完成本指南后,您将拥有一个完整的AI 驱动安全系统,它
  • ✅ 使用自然语言 — 简单的提示代替复杂的 CLI 命令
  • ✅ 自动修复 — AI 建议并验证安全修复
  • ✅ 持续运行 — 在 CI/CD 管道中自动扫描
  • ✅ 强制执行防护 — 安全规则阻止易受攻击的代码发布

持续人工智能

您的安全工作流现在运行在持续 AI 第 2 级——AI 处理常规安全扫描和补救,通过人工审查和批准修复方案进行监督。

后续步骤

  1. 运行您的首次扫描 - 在您当前的项目上尝试 SAST 提示
  2. 审查发现 - 分析安全报告并实施修复
  3. 设置 CI 管道 - 将 GitHub Actions 工作流添加到您的仓库
  4. 自定义规则 - 添加项目特定的安全策略
  5. 监控趋势 - 跟踪 漏洞 随时间减少的情况

其他资源