> 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/custom-code-context-for-sast-rules.md).

# SASTルールのためのカスタムコードコンテキスト

Custom Code Context を使うと、特定の SAST ルールに平易な言葉でのガイダンスを追加できます。Aikido はそのガイダンスを使って [AutoTriage](/docs/docs-ja/kdosukyan/scanning-practices/sast-autotriage.md) より適切に真陽性・偽陽性を判断するために使います。コンテキストはグローバルにも、リポジトリ単位でも追加できます。

これは **しません** ルールが検出する内容を変更するものではありません。Aikido が検出結果をより正確に解釈するのに役立ちます。

### ユースケース

ルールがコードベース固有の知識を必要とする場合は、Custom Code Context を使います。たとえば次のような場合です：

* 信頼できるサニタイズ用ライブラリ
* 危険な API を囲む社内の安全なラッパー
* データを信頼済みとして扱うバリデーションヘルパー
* あるリポジトリでのみ安全なパターン
* 信頼できる入力を扱う、隔離されたマシン上で動作するスクリプト

<details>

<summary>具体例を表示</summary>

**信頼できるサニタイズ用ライブラリ**

{% code overflow="wrap" %}

```
サニタイズには公開ライブラリ <L> をよく使います。このライブラリの関数が返すすべての変数は、信頼済みと見なされます。
```

{% endcode %}

**社内のバリデーションヘルパー**

{% code overflow="wrap" %}

```
このルールでは、validateAndNormalizeUserInput() が返す値はサニタイズ済みと見なされます。このヘルパーは無効な文字を拒否し、厳格な許可リストを適用します。
```

{% endcode %}

**危険な API を囲む安全なラッパー**

{% code overflow="wrap" %}

```
このルールでは、safeRedirect() を介した呼び出しは想定内です。このラッパーは、承認済みドメインの許可リストに含まれる URL へのリダイレクトのみを許可します。
```

{% endcode %}

</details>

### コンテキストの追加方法

{% hint style="info" %}
Custom Code Context は、AutoTriage に対応している SAST ルールでのみ利用できます。
{% endhint %}

**手順 1。** Repositories Checks ページを開き、「[SAST ルールを表示](https://app.aikido.dev/repositories/sast)'.

**手順 2。** 該当する SAST ルールを見つけ、アクションメニューを開いて選択します **Custom Code Context**.<br>

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

**手順 3。** 平易な言葉でコンテキストを追加します。

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

**手順 4。** コンテキストを全体に適用するか、そのリポジトリだけに適用するかを選び、変更を保存します。

{% hint style="info" %}
新しいコンテキストを適用する前に、手動での再スキャンが必要です。
{% endhint %}

### 記述のヒント

コンテキストは狭く、具体的に保ってください。

すること:

* 正確なライブラリ、関数、ラッパー、またはフォルダ名を挙げる
* データがなぜ信頼できる、またはサニタイズ済みといえるのかを説明する
* 選択したルールに固有の内容にする

避けるもの：

* 「入力は通常サニタイズされている」のような曖昧な主張
* 関数名のない曖昧な記述
* すべてに当てはまる例外

<details>

<summary>良い例と弱い例を表示</summary>

**良い例**

{% code overflow="wrap" %}

```
この SQL インジェクション ルールでは、buildSafeQuery() が返す値は信頼済みです。このヘルパーはパラメータ化クエリのみを作成し、未加工のユーザー入力を連結することはありません。
```

{% endcode %}

**弱い例**

{% code overflow="wrap" %}

```
私たちのチームは SQL クエリを慎重に扱っているので、これらの検出結果はしばしば誤検知です。
```

{% endcode %}

</details>

### Custom Code Context とカスタム SAST ルール

既存のルールのトリアージを改善したい場合は、Custom Code Context を使います。

使用 [カスタム SAST ルール](/docs/docs-ja/kdosukyan/scanning-practices/add-custom-sast-iac-rules.md) コードベース内の新しいパターンを検出する必要がある場合に使います。

要するに：

* **Custom Code Context** 解釈を洗練する
* **カスタム SAST ルール** 検出対象を拡大する


---

# 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/custom-code-context-for-sast-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.
