> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/kdosukyan/scanning-practices/add-custom-sast-iac-rules.md).

# カスタム SAST & IaC ルールを追加する

## はじめに <a href="#introduction" id="introduction"></a>

これらのカスタムルールを使用すると、Aikido にコードベース内の特定のリスク、特にお使いの環境に非常に関連性の高いリスクをスキャンさせることができます。これにより、より広範な SAST または IaC ルールでは見落とされる可能性のある脆弱性を検出できます。

## 手順ガイド <a href="#step-by-step-guide" id="step-by-step-guide"></a>

{% hint style="info" %}
この機能は、デフォルトではワークスペースで有効になっていません。有効にするには Aikido にお問い合わせください。
{% endhint %}

**手順 1:** へ移動 [リポジトリのチェック](https://app.aikido.dev/repositories/checks) ページ。

**手順 2:** 「をクリック[カスタムルールを作成](https://app.aikido.dev/repositories/sast/custom/add)」を SAST セクションで\
​

![カスタムのセキュリティおよびコンプライアンスルールを作成するためのオプションがあるリポジトリチェックのダッシュボード。](/files/ff5ea2dc52ee6bdda5248157e3e3b6fc534f708c)

​**手順 3:** ルールに次の詳細を入力してください:

* **Opengrep ルール:** Aikido が検索するルールを定義します。 **ヒント:** を使用 [Opengrep プレイグラウンド](https://github.com/opengrep/opengrep-playground?tab=readme-ov-file#installation)[ ](https://semgrep.dev/playground)保存する前に、ルールの有効性をテストします。
* **タイトル:** ルールにわかりやすい名前を付けます。
* **要約:** 問題の簡潔な説明を入力してください。これはサイドバーに表示されます。
* **修正方法:** チームに、この問題を修正する最善の方法を伝えてください。
* **言語:** プログラミング言語を指定します。
* **Aikido スコア:** メインフィードでの問題報告の優先度を設定します。

<figure><img src="/files/dfd71190e9c033a3a785cf2bb6d23c1f87f5b48a" alt=""><figcaption></figcaption></figure>

**手順 4:** ルールの設定に満足したら、「保存」をクリックして Aikido SAST チェックに追加します。カスタムルールは現在有効で、今後のスキャンに自動的に適用されます。

### 補足情報 <a href="#extra-info" id="extra-info"></a>

* 全体として、Opengrep ルールの language 属性が常に優先されます。これは、すべての言語とファイルに一度に適用する必要があるカスタムルールを実装したい場合に役立ちます。
* IaC ルールを作成したい場合は、language を yaml/terraform/... に設定することで実現できます。

## 例 <a href="#examples" id="examples"></a>

* **SAST ルール:** JavaScript で弱い MD5 ハッシュアルゴリズムの使用を探します。

  ```
  rules:
    - id: CUSTOM-RULE-XXXX
      message: MD5 が使用されているようです 
      languages:
        - javascript
      paths: 
        include
          - "*.js"
      severity: WARNING
      pattern-either:
        - pattern: $CRYPTO.createHash("md5")
        - pattern: CryptoJS.MD5(...)
  ```
* **IaC ルール:** 危険な可能性のある lambda 関数を検出するためのカスタムルール。

  ```
  rules:
     - id: CUSTOM-RULE-530
       languages:
         - hcl
       severity: WARNING
       message: >
         "type:monitored" タグはあるが、"service" タグがない Lambda 関数が見つかりました。
       patterns:
         - pattern: |-
             resource "aws_lambda_function" $ANYTHING {
               ...
               tags = {..., type = "monitored", ...}
             }
         - pattern-not: |-
             resource "aws_lambda_function" $ANYTHING {
               ...
               tags = {..., service= "...", ...}
             }
  ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.aikido.dev/docs/docs-ja/kdosukyan/scanning-practices/add-custom-sast-iac-rules.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
