> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/autify-university/integrations/securing-your-webhooks.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Webhookをより安全に利用する

## はじめに

Webhook URLを設定した場合、そのURLへのリクエストが実際にAutifyから送られたものかどうかを確認するためにWebhookシークレットも併せて設定することを推奨します。このドキュメントではWebhookシークレットがない場合のリスクや、生成・設定・確認方法について説明します。

## Webhookシークレットとは

Webhook URLはインターネット上に公開する必要があります。そのため、そのURLに対するリクエストが、常にAutifyから送信されているという保証はどこにもありません。また、中間者攻撃などにより、Webhookのリクエストが改ざんされてしまう可能性もあります。

これらのリスクに対応するために、ユーザーはWebhookシークレットを設定することができます。Webhookシークレットとは、受け取ったWebhookリクエストを検証するために、ユーザーとAutifyだけが共有する任意の文字列（秘密鍵）のことです。この値はユーザーが作成してAutifyに設定する必要があります。

Autifyとユーザーは、同じWebhookシークレットを使って、同じアルゴリズムで **ペイロード**（ここではHTTPリクエストのボディ全文を指します）の **HMAC** （暗号化された文字列）を生成します。この2つを比較することで、ユーザーは以下のことを確認することができます。

* リクエストの送信元が、Webhookシークレットを **知っている** こと。Webhookシークレットを、Autifyとユーザー以外の第三者に誤って公開しない限り、受信したリクエストが間違いなくAutifyからのものであると確認できます。
* 送信されたリクエストが **改ざんされたものでない** こと。HMACは、リクエストを送信した時点で生成されたものなので、リクエストが送信されてからWebhook URLに届くまでの経路で改ざんされていないと確認できます。

## Webhookシークレットを使ったリクエストの検証

Webhookシークレットを設定すると、Autifyからのリクエストヘッダに`X-Autify-Signature`が含まれます。この値は、AutifyがリクエストとWebhookシークレットを用いて生成したハッシュ値です。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-e2825f37cf2c68cb514876503a6527015ed2b818%2Fzndsk-webhook_secret.png?alt=media)

## Webhookシークレットの生成及び設定方法

1. ワークスペース設定ページのWebhookセクションで新規作成、もしくは既存のものを選択
2. Webhookシークレットを生成。値はランダムに生成するなど、**推測されにくい** ものを使用してください。以下は、コマンドラインによるランダム値の生成方法です。

```
# ランダム値の生成例
＄ openssl rand -hex 20b2f82af62f9980f6b01e1cd7e716230d0a063f58
```

3. Webhookシークレットに前のステップで取得した値を入力
4. 作成または更新ボタンを押下

## Webhookシークレットを用いたペイロードの検証方法

以下のように、ペイロードのHMACを生成し、リクエストヘッダに記載されたものと比較します。

1. Webhookシークレットを用いてペイロードのHMACを計算
2. (1)で取得した値を`sha1=`の末尾に結合
3. 受け取ったリクエストヘッダ`X-Autify-Signature`の値を取得
4. (2)と(3)で取得した値を比較して一致することを確認
   * ※ 値が一致しない場合、Autify以外からのリクエストの可能性があります。

以下は各言語での確認方法のサンプルです：

### Ruby

```ruby
$ gem install rack
```

```ruby
require 'openssl'
require 'rack'

digest = OpenSSL::HMAC.hexdigest(
  OpenSSL::Digest.new('sha1'),
  '<Webhookシークレット>',
  '<ペイロード>'
)

computed_signature = "sha1=${digest}"
request_signature  = '<X-Autify-Signature>'

Rack::Utils.secure_compare(
  computed_signature, 
  request_signature
)
```

### Node.js

```javascript
const crypto = require('crypto');

const digest = crypto
  .createHmac('sha1','<Webhookシークレット>')
  .update('<ペイロード>')
  .digest('hex')

const computedSignature = `sha1=${digest}`
const requestSignature  = '<X-Autify-Signature>'

crypto.timingSafeEqual(
  Buffer.from(computedSignature, 'utf8'), 
  Buffer.from(requestSignature, 'utf8')
)
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/autify-university/integrations/securing-your-webhooks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
