Contrast AI SmartFixのセットアップ
法的免責事項
Contrast AI SmartFixを使用すると、コードおよびその他のデータが、お客様が選択したLLMに送信されることに同意したことになります。LLMへのデータの送信およびLLMによって生成された出力の両方に、そのLLMの利用規約が適用されます。Contrast AI SmartFixの使用は、全てお客様自身の責任において行われるものとします。
Contrast AI SmartFixを使用するには、GitHubリポジトリにワークフローファイル(例、.github/workflows/smartfix.yml
)を追加します。
注記
この機能を利用するには、Contrastの担当者までお問い合わせください。
開始する前に
Contrast Assess:アプリケーションでContrast Assessが有効になっていることを確認して下さい。
サポートされる脆弱性:重大および高
GitHub:プロジェクトがGitHubでホストされ、GitHub Actionsを使用していることを確認して下さい。
API専用ユーザ:Contrastで、「組織の閲覧」アクションと「アプリケーションの編集」アクションがあるロールを持つAPI専用サービスユーザを作成して下さい。
Contrastの認証情報:Contrastのホスト名、組織ID、アプリケーションID、認証キー、APIキーが必要です。
組織ID、認証キー、APIキーは、Contrast Webインターフェイスのユーザ設定で確認できます。アプリケーションIDを調べるには、Contrast Webインターフェイスの「アプリケーション」ページで、アプリケーションを選択します。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.com
contrast_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のワークフロー例
以下の例は、.github/workflows/smartfix.yml
ワークフローファイルに 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アプリケーションID | はい | |
| Contrast Security APIホスト(例、 | はい | |
| Contrastの組織ID | はい | |
| 詳細ログを有効にします。 | いいえ |
|
| Contrastに送信されるテレメトリデータの量を制御します。
| いいえ |
|
| コードをフォーマットするコマンド | いいえ | |
| 脆弱性を処理する内部エージェントあたりのイベントの最大数 | いいえ |
|
| SmartFixで同時に開くことができるプルリクエストの最大数 | いいえ |
|
| 修正の実装後にビルドが失敗した場合のQA介入の最大試行回数 | いいえ |
|
| Contrast認証キー この値はGitHubシークレットとして保存する必要があります。 | はい | |
| PRを行うためのGitHubトークン この値はGitHubシークレットとして保存する必要があります。 | はい | |
| QAレビューステップ(ビルド検証)をスキップ | いいえ |
|
| 修正プログラムのセキュリティ テストの作成をスキップ | いいえ |
|
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
を指定します。