設定するContrast AI SmartFix
法的免責事項
Contrast AI SmartFixをご利用になる場合、お客様のコードおよびその他のデータは、お客様が選択するLLMに送信されることに同意するものとします。LLMへのデータ送信およびLLMによって生成された出力は、いずれも当該Contrast AI SmartFixLLMの利用規約が適用されます。Contrast AI SmartFixの利用は、完全に自己責任となります。
Contrast AI SmartFixを使用するには、GitHubリポジトリにワークフローファイル(例、.github/workflows/smartfix.yml)を追加します。
開始する前に
Contrast Assess:アプリケーションでContrast Assessが有効になっていることを確認して下さい。
サポートされる脆弱性:重大および高
サポートされている言語: Java、.NET Core、.NET Framework、Node.js、Python。
GitHub:プロジェクトがGitHubでホストされ、GitHub Actionsを使用していることを確認して下さい。
API専用ユーザ:Contrastで、「組織の閲覧」アクションと「アプリケーションの編集」アクションがあるロールを持つAPI専用サービスユーザを作成して下さい。
Contrastの認証情報:Contrastのホスト名、組織ID、アプリケーションID、認証キー、APIキーが必要です。
Contrastウェブインターフェースのユーザー設定で、組織ID、認証キー、およびAPIキーを見つけることができます。アプリケーションIDを確認するには、Contrastウェブインターフェースの「アプリケーション」ページでアプリケーションを選択します。URL内の
applications/の後の数字がIDです。ビルド コマンド:アプリケーションをビルドしてテストを実行するための信頼できるコマンドがあることを確認します。例えば、
mvn clean verifyやgradle clean build testなどのコマンドを使用できます。このコマンドは、SmartFixのワークフローに含める必要があります。
大規模言語モデル(LLM)のアカウントとAPIキー:例えば、Bedrockの場合はAWSアカウント、直接Anthropic APIを使用する場合はAnthropicアカウントなど。
推奨されるLLM:Anthropic Claude Sonnet(例、AWS Bedrockや直接Anthropic APIを使用するClaude 3.7 Sonnet)。
LiteLLMのドキュメントに、
agent_modelに対する文字列の情報が記載されています。除外:クロスサイト リクエスト フォージェリ (CSRF) は、修正が複雑で API の変更が必要になることが多いため、現在除外されています。Contrastによる継続的なテストに基づいて、その他の特定の脆弱性の種類は除外される場合があります。
SmartFixベストプラクティス
まずは1つのアプリケーションから:SmartFixのワークフローを知り、最適な設定を理解するために、最初は1つのアプリケーションで試してみましょう。
PRのレビューとテスト:SmartFixでは正確な修正を目指していますが、生成されたPRをコードベースにマージする前に、必ずレビューとテストを行って下さい。
max_open_prsの微調整:max_open_prs設定(プルリクエスト数)は、PRのレビューとマージを行う担当の許容範囲に応じて調整して下さい。特定 LLMバージョンの使用:一貫した結果を得るには、使用するLLMを特定のバージョンに固定して下さい。
手順
ワークフローファイルを作成:GitHubのリポジトリに、新しいワークフローファイルを作成します。
SmartFixワークフロー例を参考として使用するか、https://github.com/Contrast-Security-OSS/contrast-ai-smartfix-action/blob/main/contrast-ai-smartfix.yml.templateの完全な例を参照して下さい。
Contrastの認証情報を設定:ワークフローファイルに、以下のContrastの認証情報を含めます。
contrast_host: プロトコルを含む Contrast インスタンスのホスト名。例:https://yourcompany.contrastsecurity.comcontrast_org_id:Contrastの組織のUUIDcontrast_app_id:リポジトリにあるアプリケーションの固有のUUIDcontrast_authorization_key:(推奨)サービスユーザを作成して、そのユーザの認証キー(エージェントキー)を使うことをお勧めします。contrast_api_key: 組織のAPI キー
推奨:APIキーや認証キーなど、機密性の高い情報は全てGitHubシークレットとして保存することをお勧めします。
GitHubの設定:プルリクエストを行うための
github_tokenやbase_branchなど、GitHubの設定を行います。ビルド コマンドを設定します。SmartFix変更がプロジェクトで正しく機能することを確認するには、
build_commandが必要です。プロジェクトに適したコマンド(例えば、mvn clean installなど)を使用してください。LLMを設定:LLM プロバイダーを選択し、ワークフローファイルに必要な認証情報を設定して下さい。
推奨:Anthropic Claude Sonnet
SmartFixワークフロー例
この例は、SmartFix ワークフローファイルでを設定する方法を示しています。LLMとしてAnthropic Claude Sonnetを使用しています。
#-
# #%L
# Contrast AI SmartFix
# %%
# Copyright (C) 2025 Contrast Security, Inc.
# %%
# Contact: support@contrastsecurity.com
# License: Commercial
# NOTICE: This Software and the patented inventions embodied within may only be
# used as part of Contrast Security’s commercial offerings. Even though it is
# made available through public repositories, use of this Software is subject to
# the applicable End User Licensing Agreement found at
# https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
# between Contrast Security and the End User. The Software may not be reverse
# engineered, modified, repackaged, sold, redistributed or otherwise used in a
# way not consistent with the End User License Agreement.
# #L%
#
name: Contrast AI SmartFix
on:
pull_request:
types:
- closed
schedule:
- cron: '0 0 * * *' # <-- Customer configured schedule
workflow_dispatch: # Allows manual triggering
permissions:
contents: write
pull-requests: write
jobs:
generate_fixes:
name: Generate Fixes
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Contrast AI SmartFix - Generate Fixes Action
uses: Contrast-Security-OSS/contrast-ai-smartfix-action@v1
with:
# --- Max Open PRs ---
max_open_prs: 5
# --- Base Branch ---
base_branch: '${{ github.event.repository.default_branch }}'
# --- Build Command ---
build_command: 'mvn clean test'
# --- Formatting Command ---
formatting_command: 'mvn spotless:apply'
# --- Max QA Intervention loop attempts ---
max_qa_attempts: 6
# --- GitHub Token ---
github_token: ${{ secrets.GITHUB_TOKEN }}
# --- Contrast API Credentials ---
contrast_host: ${{ vars.CONTRAST_HOST }}
contrast_org_id: ${{ vars.CONTRAST_ORG_ID }}
contrast_app_id: ${{ vars.CONTRAST_APP_ID }}
contrast_authorization_key: ${{ secrets.CONTRAST_AUTHORIZATION_KEY }}
contrast_api_key: ${{ secrets.CONTRAST_API_KEY }}
# --- Google Gemini API Credentials ---
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
# --- Anthropic API Credentials ---
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
# --- Azure Open API Credentials ---
# azure_api_key: ${{ secrets.AZURE_API_KEY }}
# azure_api_base: ${{ secrets.AZURE_API_BASE }}
# azure_api_version: ${{ secrets.AZURE_API_VERSION }}
# --- Agent Configuration ---
agent_model: ${{ vars.AGENT_MODEL || 'bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0' }}
# Other Optional Inputs (see action.yml for defaults and more options)
# formatting_command: 'mvn spotless:apply' # Or the command appropriate for your project to correct the formatting of SmartFix\'s changes. This ensures that SmartFix follows your coding standards.
# max_open_prs: 5 # This is the maximum limit for the number of PRs that SmartFix will have open at single time
# enable_full_telemetry: 'false' # Set to false to disable full telemetry
handle_pr_merge:
name: Handle PR Merge
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && contains(github.event.pull_request.head.ref, 'smartfix/remediation-')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Notify Contrast on PR Merge
uses: Contrast-Security-OSS/contrast-ai-smartfix-action@v1
with:
run_task: merge
# --- GitHub Token ---
github_token: ${{ secrets.GITHUB_TOKEN }}
# --- Contrast API Credentials ---
contrast_host: ${{ vars.CONTRAST_HOST }}
contrast_org_id: ${{ vars.CONTRAST_ORG_ID }}
contrast_app_id: ${{ vars.CONTRAST_APP_ID }}
contrast_authorization_key: ${{ secrets.CONTRAST_AUTHORIZATION_KEY }}
contrast_api_key: ${{ secrets.CONTRAST_API_KEY }}
env:
GITHUB_EVENT_PATH: ${{ github.event_path }}
handle_pr_closed:
name: Handle PR Close
runs-on: ubuntu-latest
if: github.event.pull_request.merged == false && contains(github.event.pull_request.head.ref, 'smartfix/remediation-')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Notify Contrast on PR Closed
uses: Contrast-Security-OSS/contrast-ai-smartfix-action@v1
with:
run_task: closed
# --- GitHub Token ---
github_token: ${{ secrets.GITHUB_TOKEN }}
# --- Contrast API Credentials ---
contrast_host: ${{ vars.CONTRAST_HOST }}
contrast_org_id: ${{ vars.CONTRAST_ORG_ID }}
contrast_app_id: ${{ vars.CONTRAST_APP_ID }}
contrast_authorization_key: ${{ secrets.CONTRAST_AUTHORIZATION_KEY }}
contrast_api_key: ${{ secrets.CONTRAST_API_KEY }}
env:
GITHUB_EVENT_PATH: ${{ github.event_path }}SmartFix設定入力
最新の入力項目とデフォルト値は、SmartFix GitHub Actionリポジトリのaction.ymlファイルに記載されています。
入力項目 | 説明 | 必須項目? | デフォルト |
|---|---|---|---|
| 使用するLLMモデル | いいえ |
|
| アプリケーションをビルドするコマンド(例、 | はい | |
| Contrast APIキー | はい | |
| Contrastに送信されるテレメトリーデータの量を制御します。
| いいえ |
|
| コードをフォーマットするコマンド | いいえ | |
| PRを行うためのGitHubトークン この値はGitHubシークレットとして保存する必要があります。 | はい | |
| 脆弱性を処理する内部エージェントあたりの最大イベント数 | いいえ |
|
| SmartFixで同時に開くことができるプルリクエストの最大数。 | いいえ |
|
| 修正の実装後にビルドが失敗した場合のQA介入の最大試行回数 | いいえ |
|
| QAレビューステップ(ビルド検証)をスキップ | いいえ |
|
| 修正プログラムのセキュリティ テストの作成をスキップ | いいえ |
|
| リポジトリのContrastアプリケーションID | はい | |
| Contrast Security APIホスト(例、 | はい | |
| Contrastの組織ID | はい | |
| 詳細ログを有効にします。 | いいえ |
|
| リポジトリのデフォルトブランチ | いいえ |
|
| Contrast認証キー この値はGitHubシークレットとして保存する必要があります。 | はい |
LLM設定
推奨:Anthropic API直接利用の設定:
agent_modelにAnthropicの適切なモデルの文字列を設定します(例、anthropic/claude-3-7-sonnet-20250219)。anthropic_api_keyを指定します。
推奨: AWS Bedrock利用の設定
agent_modelに適切なモデルの文字列を設定します(例、bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0)。AWSの認証情報(
aws_access_key_id、aws_secret_access_key、aws_region)を指定します。
試験段階:Google Gemini Pro利用の設定(例、Gemini 2.5 Pro)
agent_modelに適切なモデルの文字列を(例、gemini/gemini-1.5-pro-latest)を設定します。gemini_api_keyを指定します。
Contrast AI SmartFixAIコーディングエージェントとの統合
SmartFix GitHub Action リポジトリには、特定のAIコーディングエージェントとの統合に関する詳細な手順が含まれています
AIコーディングエージェント | 統合手順 |
|---|---|
Claude Code | |
GitHub Copilot |