Webhook 集成

通过 Webhook 接收实时事件通知


Webhook 允许您在发生重要事件时接收实时通知,便于与您的系统集成。

配置 Webhook

  1. 进入 设置 > 集成 > Webhook
  2. 点击 添加 Webhook
  3. 输入您的 Webhook URL
  4. 选择要订阅的事件类型
  5. 保存并测试

事件类型

事件描述
threat.created新威胁被创建
threat.updated威胁状态更新
threat.resolved威胁已解决
scan.started扫描任务开始
scan.completed扫描任务完成
beacon.triggeredBeacon 信标被触发
token.accessed蜜罐令牌被访问

请求格式

POST /your-webhook-url
Content-Type: application/json
X-OpenBait-Signature: sha256=...

{
  "id": "evt_xxx",
  "type": "threat.created",
  "created_at": "2024-01-20T10:30:00Z",
  "data": {
    "threat": {
      "id": "thr_xxx",
      "domain": "examp1e.com",
      "type": "phishing",
      "severity": "high",
      "similarity": 0.95
    }
  }
}

验证签名

为确保请求来自 OpenBait,请验证签名:

const crypto = require('crypto')

function verifySignature(payload, signature, secret) {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex')

  return `sha256=${expected}` === signature
}

// Express 示例
app.post('/webhook', (req, res) => {
  const signature = req.headers['x-openbait-signature']
  const isValid = verifySignature(
    JSON.stringify(req.body),
    signature,
    process.env.WEBHOOK_SECRET
  )

  if (!isValid) {
    return res.status(401).send('Invalid signature')
  }

  // 处理事件
  const { type, data } = req.body

  switch (type) {
    case 'threat.created':
      handleNewThreat(data.threat)
      break
    // ...
  }

  res.status(200).send('OK')
})

重试策略

如果您的 Webhook 端点返回非 2xx 状态码,OpenBait 会按以下策略重试:

  • 第 1 次重试:1 分钟后
  • 第 2 次重试:5 分钟后
  • 第 3 次重试:30 分钟后
  • 第 4 次重试:2 小时后

超过 4 次重试后,该事件将被标记为失败。


    Webhook 集成 | OpenBait