mcpField
I
implementing-api-threat-protection-with-apigee

implementing-api-threat-protection-with-apigee

github.com/mukul975セキュリティ35.2k107 回インストール8 週間前に更新
リポジトリ

implementing-api-threat-protection-with-apigee について

Google Apigee のポリシーを設定し、不正な形式のコンテンツ、インジェクションパターン、急増するトラフィック、無効な認証情報から API を保護する実践的なスキルです。Apigee プロキシで API セキュリティ制御を導入するチーム向けです。

主な機能

  1. 01JSON と XML の検証ポリシー
  2. 02正規表現によるインジェクション対策
  3. 03SpikeArrest によるレート制限
  4. 04OAuth 2.0 と API キーの検証
  5. 05Advanced API Security の設定

活用シーン

  1. 01API プロキシにリクエスト検証を適用
  2. 02バックエンドサービスへの急増トラフィックを制限
  3. 03トークンと API キーを検査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill implementing-api-threat-protection-with-apigee

インストール後、Claude Code で/implementing-api-threat-protection-with-apigeeを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
references/
api-reference.md
scripts/
agent.py

詳細

Apigee による API 脅威保護の実装

概要

Google Apigee は、JSON および XML コンテンツの検証、OAuth 2.0 の適用、SpikeArrest によるレート制限、正規表現による脅威保護、悪意のあるクライアントや API の不正利用パターンを検出する Advanced API Security など、脅威保護のためのネイティブセキュリティポリシーを提供するエンタープライズ API 管理プラットフォームです。Apigee はリバースプロキシとして動作し、すべての API トラフィックを中継して、リクエストがバックエンドサービスに到達する前にセキュリティポリシーを適用することで、OWASP API Security Top 10 の脅威から API を効果的に保護します。

使用するタイミング

  • 環境に Apigee による API 脅威保護機能を導入または設定する場合
  • コンプライアンス要件に沿ったセキュリティ制御を確立する場合
  • この分野のセキュリティアーキテクチャを構築または改善する場合
  • この実装を必要とするセキュリティ評価を実施する場合

前提条件

  • Apigee 組織がプロビジョニングされた Google Cloud Platform アカウント
  • 設定済みの Apigee X または Apigee hybrid 環境
  • Apigee からアクセス可能な、デプロイ済みのバックエンド API サービス
  • インストール済みで認証済みの Google Cloud CLI(gcloud)
  • 対象 API の OpenAPI 仕様
  • Apigee プロキシバンドル構造に関する知識

主なセキュリティポリシー

1. JSON 脅威保護

構造の深さ、エントリ数、文字列の長さを制限して、JSON を利用したサービス拒否攻撃から保護します。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection</DisplayName>
    <Source>request</Source>
    
    <ObjectEntryNameLength>50</ObjectEntryNameLength>
    <ObjectEntryCount>25</ObjectEntryCount>
    <ArrayElementCount>100</ArrayElementCount>
    <ContainerDepth>5</ContainerDepth>
    <StringValueLength>500</StringValueLength>
</JSONThreatProtection>
2. XML 脅威保護

XML 爆弾、XXE 攻撃、サイズの大きすぎる XML ペイロードから保護します。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLThreatProtection name="XML-Threat-Protection-1">
    <DisplayName>XML Threat Protection</DisplayName>
    <Source>request</Source>
    <NameLimits>
        <Element>50</Element>
        <Attribute>50</Attribute>
        <NamespacePrefix>20</NamespacePrefix>
        <ProcessingInstructionTarget>50</ProcessingInstructionTarget>
    </NameLimits>
    <ValueLimits>
        <Text>1000</Text>
        <Attribute>500</Attribute>
        <NamespaceURI>256</NamespaceURI>
        <Comment>256</Comment>
        <ProcessingInstructionData>256</ProcessingInstructionData>
    </ValueLimits>
    <StructureLimits>
        <NodeDepth>5</NodeDepth>
        <AttributeCountPerElement>5</AttributeCountPerElement>
        <NamespaceCountPerElement>3</NamespaceCountPerElement>
        <ChildCount>25</ChildCount>
    </StructureLimits>
</XMLThreatProtection>
3. 正規表現による脅威保護

リクエストパラメーター内の SQL インジェクション、XSS、その他のインジェクションパターンを検出します。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RegularExpressionProtection name="RegEx-Threat-Protection-1">
    <DisplayName>Regex Injection Protection</DisplayName>
    <Source>request</Source>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

    
    <QueryParam name="*">
        <Pattern>[\s]*((delete)|(exec)|(drop\s*table)|(insert)|(shutdown)|(update)|(\bor\b))</Pattern>
    </QueryParam>

    
    <QueryParam name="*">
        <Pattern>[\s]*&lt;\s*script\b[^&gt;]*&gt;[^&lt;]+&lt;\s*/\s*script\s*&gt;</Pattern>
    </QueryParam>

    
    <Header name="*">
        <Pattern>[\r\n]</Pattern>
    </Header>

    
    <URIPath>
        <Pattern>(/\.\.)|(\.\./)</Pattern>
    </URIPath>

    
    <JSONPayload>
        <JSONPath>$.*</JSONPath>
        <Pattern>[\s]*((delete)|(exec)|(drop\s*table)|(insert)|(shutdown)|(update))</Pattern>
    </JSONPayload>
</RegularExpressionProtection>
4. SpikeArrest ポリシー

トラフィックの急増によってバックエンドサービスが過負荷になるのを防ぎます。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SpikeArrest name="Spike-Arrest-1">
    <DisplayName>API Spike Arrest</DisplayName>
    <Rate>30ps</Rate> 
    <Identifier ref="request.header.x-api-key"/>
    <MessageWeight ref="request.header.x-request-weight"/>
    <UseEffectiveCount>true</UseEffectiveCount>
</SpikeArrest>
5. OAuth 2.0 トークンの検証
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OAuthV2 name="Verify-OAuth-Token">
    <DisplayName>Verify OAuth 2.0 Access Token</DisplayName>
    <Operation>VerifyAccessToken</Operation>
    <ExternalAuthorization>false</ExternalAuthorization>
    <ExternalAccessToken>request.header.Authorization</ExternalAccessToken>
    <SupportedGrantTypes>
        <GrantType>authorization_code</GrantType>
        <GrantType>client_credentials</GrantType>
    </SupportedGrantTypes>
    <Scope>read write</Scope>
    <GenerateResponse enabled="true"/>
</OAuthV2>
6. API キーの検証
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VerifyAPIKey name="Verify-API-Key-1">
    <DisplayName>Verify API Key</DisplayName>
    <APIKey ref="request.header.x-api-key"/>
</VerifyAPIKey>

プロキシバンドルの設定

セキュアなプロキシフロー全体

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request>
            
            <Step>
                <Name>Verify-OAuth-Token</Name>
            </Step>
            
            <Step>
                <Name>Spike-Arrest-1</Name>
            </Step>
            
            <Step>
                <Name>JSON-Threat-Protection-1</Name>
                <Condition>request.header.Content-Type = "application/json"</Condition>
            </Step>
            <Step>
                <Name>XML-Threat-Protection-1</Name>
                <Condition>request.header.Content-Type = "text/xml"</Condition>
            </Step>
            
            <Step>
                <Name>RegEx-Threat-Protection-1</Name>
            </Step>
            
            <Step>
                <Name>CORS-Policy</Name>
            </Step>
        </Request>
        <Response>
            
            <Step>
                <Name>Remove-Internal-Headers</Name>
            </Step>
            
            <Step>
                <Name>Add-Security-Headers</Name>
            </Step>
        </Response>
    </PreFlow>

    <Flows>
        <Flow name="sensitive-operations">
            <Description>Additional protection for sensitive endpoints</Description>
            <Request>
                <Step>
                    <Name>Quota-Strict</Name>
                </Step>
            </Request>
            <Condition>(proxy.pathsuffix MatchesPath "/admin/**") or
                       (proxy.pathsuffix MatchesPath "/users/*/sensitive")</Condition>
        </Flow>
    </Flows>

    <HTTPProxyConnection>
        <BasePath>/v1</BasePath>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>

    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>
セキュリティヘッダーポリシー
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="Add-Security-Headers">
    <DisplayName>Add Security Response Headers</DisplayName>
    <Set>
        <Headers>
            <Header name="X-Content-Type-Options">nosniff</Header>
            <Header name="X-Frame-Options">DENY</Header>
            <Header name="Strict-Transport-Security">max-age=31536000; includeSubDomains</Header>
            <Header name="Cache-Control">no-store, no-cache, must-revalidate</Header>
            <Header name="Content-Security-Policy">default-src 'none'</Header>
            <Header name="X-Request-ID">{messageid}</Header>
        </Headers>
    </Set>
    <Remove>
        <Headers>
            <Header name="X-Powered-By"/>
            <Header name="Server"/>
        </Headers>
    </Remove>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Advanced API Security

Apigee の Advanced API Security アドオンを有効にして、機械学習ベースの脅威検出を利用します。

# Enable Advanced API Security on Apigee X instance
gcloud apigee organizations update $ORG_NAME \
  --advanced-api-security-config=enabled

# View detected abuse alerts
gcloud apigee apis security-reports list \
  --organization=$ORG_NAME \
  --environment=$ENV_NAME

# Create security action to block suspicious traffic
gcloud apigee security-actions create \
  --organization=$ORG_NAME \
  --environment=$ENV_NAME \
  --action-type=DENY \
  --condition-type=IP_ADDRESS \
  --condition-values="192.168.1.100,10.0.0.50" \
  --description="Block identified malicious IPs"

デプロイ

# Deploy proxy bundle with security policies
gcloud apigee apis deploy \
  --api=$API_NAME \
  --environment=$ENV_NAME \
  --revision=$REVISION \
  --organization=$ORG_NAME

# Validate deployment
gcloud apigee apis list-deployments \
  --api=$API_NAME \
  --organization=$ORG_NAME

参考資料

コメント