implementing-api-security-testing-with-42crunch について
API 開発者やセキュリティチーム向けの、42Crunch による API セキュリティテストのガイドです。OpenAPI の静的監査、稼働中 API の動的スキャン、ランタイム保護と修正手順を扱います。
主な機能
- 01OpenAPI 定義の監査
- 02稼働中 API の動的スキャン
- 03IDE と CI/CD への統合
- 04マイクロゲートウェイによるランタイム保護
- 05所見の優先度付けと再確認
活用シーン
- 01リリース前の API 定義のセキュリティ確認
- 02CI/CD パイプラインでの API セキュリティスキャン
- 03実行時 API と OpenAPI 契約の照合
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill implementing-api-security-testing-with-42crunchインストール後、Claude Code で/implementing-api-security-testing-with-42crunchを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
42Crunch を使用した API セキュリティテストの実装
概要
42Crunch は、シフトレフトのセキュリティテストとシールドライトのランタイム保護を組み合わせた API セキュリティプラットフォームです。OpenAPI 定義の静的セキュリティ分析を行う API Audit、動的な脆弱性検出を行う API Conformance Scan、リアルタイムの脅威防止を行う API Protect を提供します。このプラットフォームは CI/CD パイプラインや IDE と連携し、デプロイ前後に OWASP API Security Top 10 の脆弱性を特定します。
使用する場面
- 環境に 42Crunch の API セキュリティテスト機能を導入または設定する場合
- コンプライアンス要件に沿ったセキュリティ制御を確立する場合
- このドメインのセキュリティアーキテクチャを構築または改善する場合
- この実装を必要とするセキュリティ評価を実施する場合
前提条件
- 42Crunch プラットフォームのアカウント(評価用の無料プランを利用できます)
- 対象 API の OpenAPI Specification(OAS)v2.0、v3.0、または v3.1 の定義
- 42Crunch 拡張機能を備えた IDE(VS Code、IntelliJ、または Eclipse)
- CI/CD パイプライン(Jenkins、GitHub Actions、Azure DevOps、または GitLab CI)
- 動的スキャン(コンフォーマンススキャン)用の稼働中の API インスタンス
- CLI ツール用の Node.js または Python 環境
基本概念
API Audit(静的解析)
API Audit は、稼働中の API を必要とせずに、OpenAPI 定義の静的セキュリティ分析を行います。仕様を、以下のカテゴリに分類された 300 以上のセキュリティチェックに照らして評価します。
セキュリティスコアのカテゴリ:
- データ検証:スキーマ定義、パラメーター制約、レスポンス検証
- 認証:セキュリティスキームの定義、スコープ要件
- トランスポートセキュリティ:サーバー URL のスキーム、TLS 要件
- エラー処理:エラーレスポンスの定義、情報漏えいの防止
VS Code 拡張機能から API Audit を実行する方法:
- VS Code マーケットプレースから 42Crunch 拡張機能をインストールします
- OpenAPI 仕様ファイル(YAML または JSON)を開きます
- エディターのツールバーにあるセキュリティ監査アイコンをクリックします
- セキュリティスコア(0~100)と個別の指摘事項を確認します
- インラインの修正ガイダンスに従って問題に対処します
セキュリティ制御を含む OpenAPI 定義の例:
openapi: 3.0.3
info:
title: Secure User API
version: 1.0.0
servers:
- url: https://api.example.com/v1
description: Production server (HTTPS only)
security:
- BearerAuth: []
paths:
/users/{userId}:
get:
operationId: getUserById
summary: Retrieve user by ID
parameters:
- name: userId
in: path
required: true
schema:
type: string
format: uuid
pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
maxLength: 36
responses:
'200':
description: User details
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: Unauthorized
'404':
description: User not found
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
User:
type: object
required:
- id
- email
properties:
id:
type: string
format: uuid
readOnly: true
email:
type: string
format: email
maxLength: 254
name:
type: string
maxLength: 100
pattern: '^[a-zA-Z\s\-]+$'
additionalProperties: false
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
maxLength: 256
additionalProperties: false
API Conformance Scan(動的テスト)
コンフォーマンススキャンは、稼働中の API を OpenAPI コントラクトに照らして動的にテストし、OWASP API Security Top 10 の問題を含むランタイムの脆弱性を検出します。
Scan v2 の設定:
# 42c-conf.yaml
version: "2.0"
scan:
target:
url: https://api.example.com/v1
authentication:
- type: bearer
token: "${API_TOKEN}"
in: header
name: Authorization
settings:
maxScanTime: 3600
requestsPerSecond: 10
followRedirects: false
tests:
owasp:
- bola
- bfla
- injection
- ssrf
- massAssignment
- excessiveDataExposure
CLI からコンフォーマンススキャンを実行する方法:
# Install the 42Crunch CLI
npm install -g @42crunch/cicd-cli
# Run conformance scan
42crunch-cli scan \
--api-definition ./openapi.yaml \
--target-url https://api.example.com/v1 \
--token $CRUNCH_TOKEN \
--min-score 70 \
--report-format sarif \
--output scan-report.sarif
CI/CD パイプラインとの統合
GitHub Actions との統合:
name: API Security Testing
on:
push:
paths:
- 'api/**'
- 'openapi/**'
jobs:
api-security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 42Crunch API Audit
uses: 42Crunch/api-security-audit-action@v3
with:
api-token: ${{ secrets.CRUNCH_API_TOKEN }}
collection-name: "my-api-collection"
min-score: 75
upload-to-code-scanning: true
- name: 42Crunch Conformance Scan
if: github.ref == 'refs/heads/main'
uses: 42Crunch/api-conformance-scan@v1
with:
api-token: ${{ secrets.CRUNCH_API_TOKEN }}
target-url: ${{ secrets.STAGING_API_URL }}
scan-config: ./42c-conf.yaml
Jenkins パイプラインとの統合:
pipeline {
agent any
stages {
stage('API Security Audit') {
steps {
script {
def auditResult = sh(
script: '''
42crunch-cli audit \
--api-definition openapi.yaml \
--token ${CRUNCH_TOKEN} \
--min-score 75 \
--report-format json \
--output audit-report.json
''',
returnStatus: true
)
if (auditResult != 0) {
error("API Security Audit failed - score below threshold")
}
}
}
}
stage('Conformance Scan') {
when { branch 'main' }
steps {
sh '''
42crunch-cli scan \
--api-definition openapi.yaml \
--target-url ${STAGING_URL} \
--token ${CRUNCH_TOKEN} \
--scan-config 42c-conf.yaml
'''
}
}
}
post {
always {
archiveArtifacts artifacts: '*-report.*'
publishHTML([
reportDir: '.',
reportFiles: 'audit-report.html',
reportName: 'API Security Report'
])
}
}
}
API Protect(ランタイム保護)
API Protect は、API エンドポイントの前段にマイクロゲートウェイとしてデプロイされ、ランタイムに OpenAPI コントラクトを適用します。
# api-protect-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: api-protect-config
data:
protection-config.json: |
{
"apiDefinition": "/config/openapi.yaml",
"enforcement": {
"validateRequests": true,
"validateResponses": true,
"blockOnFailure": true,
"logLevel": "warn"
},
"rateLimit": {
"enabled": true,
"requestsPerMinute": 100,
"burstSize": 20
},
"allowlist": {
"contentTypes": ["application/json"],
"methods": ["GET", "POST", "PUT", "DELETE"]
}
}
修正ワークフロー
42Crunch が問題を特定した場合は、次の修正プロセスに従います。
- トリアージ:重大度(クリティカル、高、中、低)順に並べられた指摘事項を確認します
- 分析:OpenAPI 定義に欠けている具体的なセキュリティ制御を把握します
- 修正:推奨される変更を仕様に適用します
- 検証:監査を再実行し、スコアが改善したことを確認します
- デプロイ:更新した仕様を CI/CD パイプラインを通じて反映します
よくある監査指摘事項と修正方法:
| 指摘事項 | 重大度 | 修正方法 |
|---|---|---|
| 認証が定義されていない | クリティカル | securitySchemes と security requirements を追加する |
| 入力検証が不足している | 高 | type、format、pattern、maxLength の制約を追加する |
| サーバー URL に HTTP が使用されている | 高 | サーバー URL を HTTPS に変更する |
| エラーレスポンスが定義されていない | 中 | 4xx および 5xx のレスポンス定義を追加する |
| additionalProperties が制限されていない | 中 | オブジェクトスキーマで additionalProperties: false を設定する |
| レート制限が不足している | 中 | x-rateLimit 拡張機能を追加するか、API Protect を使用する |
主なセキュリティチェック
42Crunch は、次の重要なセキュリティ領域に基づいて API を評価します。
- BOLA の防止:オブジェクトレベルの認可パターンが定義されていることを検証します
- BFLA の防止:関数レベルのアクセス制御が定義されていることを確認します
- インジェクションの防止:入力パラメーターに適切な型、形式、パターンの制約が設定されていることを確認します
- データ漏えい:レスポンススキーマによって返されるプロパティが制限されていることを検証します
- セキュリティの設定ミス:認証方式、通信のセキュリティ、CORS 設定を確認します
- マスアサインメント:リクエストボディでプロパティの許可リストが明示的に使用されていることを検証します
参考資料
- 42Crunch API セキュリティプラットフォーム:https://42crunch.com/api-security-platform/
- 42Crunch のドキュメント:https://docs.42crunch.com/
- Microsoft Defender for Cloud の 42Crunch 統合:https://learn.microsoft.com/en-us/azure/defender-for-cloud/onboarding-guide-42crunch
- OWASP API Security Top 10 2023:https://owasp.org/API-Security/editions/2023/en/0x00-header/
- 42Crunch 用 Jenkins プラグイン:https://plugins.jenkins.io/42crunch-security-audit/