Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

statsig-webhooks

БесплатноЗапускает вложенные скриптыНе проверен

Receive and verify Statsig Event Webhook (Generic Webhook) requests. Use when setting up a Statsig webhook handler, debugging Statsig signature verification…

hookdeckот hookdeck★ 104 звезды на GitHub

Об этом скилле

Statsig Webhooks

When to Use This Skill

  • Setting up a Statsig Event Webhook (the "Generic Webhook" integration)
  • Debugging X-Statsig-Signature verification failures
  • Processing exposure events or config-change notifications (feature gate, experiment, or dynamic config created / updated events)
  • Handling Statsig's JSON batch payloads (arrays) and the config-change { "data": [...] } envelope
  • Answering the url_verification request Statsig has been seen to send when the integration is saved

Essential Code (USE THIS)

Statsig signs every webhook request with HMAC-SHA256 using a Slack/Stripe-style scheme (this is not the Standard Webhooks spec). The signed content is the literal string v0:{timestamp}:{raw_body}, and the result is sent as X-Statsig-Signature: v0=<hex>. Use the raw request body — parsing JSON before verifying will change byte ordering and break the signature.

Note: Statsig's example basestring uses a 13-digit X-Statsig-Request-Timestamp (1671672194836), a Unix time in milliseconds, not seconds.

URL Verification Request

Statsig's public docs don't describe it, but when the Generic Webhook integration is saved, Statsig has been seen to POST a verification request to the destination URL and to expect the code echoed back:

{ "data": { "event": "url_verification", "verification_code": "abc123" } }

Respond 200 with a JSON body carrying the same value:

{ "verification_code": "abc123" }

Answer it before enforcing signature verification: it only echoes a value the caller supplied. If no events arrive after you enable the integration, open its Debug tool, which lists the requests Statsig made to the webhook. The Express handler below includes the responder.

Statsig Signature Verification (JavaScript)

const crypto = require('crypto');

function verifyStatsigRequest(rawBody, signatureHeader, timestampHeader, signingSecret) {
  if (!signatureHeader || !timestampHeader || !signingSecret) return false;

  // Statsig's timestamp is a Unix time in MILLISECONDS (13 digits)
  const timestamp = parseInt(timestampHeader, 10);
  if (Number.isNaN(timestamp)) return false;

  // Replay protection (best practice; Statsig does not document a tolerance):
  // reject requests whose timestamp is more than 5 minutes from now.
  if (Math.abs(Date.now() - timestamp) > 5 * 60 * 1000) return false;

  // Statsig signs the literal string: "v0:" + timestamp + ":" + raw body
  const basestring = `v0:${timestampHeader}:${rawBody}`;
  const expected = 'v0=' + crypto
    .createHmac('sha256', signingSecret)
    .update(basestring, 'utf8')
    .digest('hex');

  try {
    return crypto.timingSafeEqual(
      Buffer.from(signatureHeader),
      Buffer.from(expected)
    );
  } catch {
    return false;
  }
}

Express Webhook Handler

const express = require('express');
const app = express();

// CRITICAL: Use express.raw() - Statsig signs the raw body, not parsed JSON
app.post('/webhooks/statsig',
  express.raw({ type: 'application/json' }),
  (req, res) => {
    const signature = req.headers['x-statsig-signature'];
    const timestamp = req.headers['x-statsig-request-timestamp'];
    const rawBody = req.body.toString('utf8');
    const payload = JSON.parse(rawBody);

    // URL validation handshake (sent when the integration is saved):
    // echo the code back or the webhook never registers.
    if (payload?.data?.event === 'url_verification') {
      return res.status(200).json({ verification_code: payload.data.verification_code });
    }

    if (!verifyStatsigRequest(rawBody, signature, timestamp, process.env.STATSIG_WEBHOOK_SECRET)) {
      return res.status(401).send('Invalid signature');
    }

    // Statsig delivers batches. Config changes arrive as { data: [...] };
    // exposure events arrive as a top-level JSON array.
    const items = Array.isArray(payload) ? payload : (payload.data || []);

    for (const item of items) {
      const meta = item.metadata || {};
      if (item.eventName === 'statsig::config_change') {
        // Config change: type e.g. "Gate" | "Experiment", action e.g. "created" | "updated"
        console.log(`Config change: ${meta.type} "${meta.name}" ${meta.action ?? 'changed'}`);
      } else if (/^statsig::.+_exposure$/.test(item.eventName)) {
        // statsig::gate_exposure, statsig::config_exposure, statsig::experiment_exposure
        console.log(`Exposure event: ${item.eventName}`);
      } else {
        // Custom events keep the name they were logged with
        console.log(`Custom event: ${item.eventName}`);
      }
    }

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

Python Signature Verification (FastAPI)

import hmac
import hashlib
import time

def verify_statsig_request(raw_body: bytes, signature_header: str, timestamp_header: str, signing_secret: str) -> bool:
    if not signature_header or not timestamp_hea
Полный SKILL.md на GitHub

Установить statsig-webhooks в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/express/.env.exampleexamples/express/README.mdexamples/express/package.jsonexamples/express/src/index.jsexamples/fastapi/.env.exampleexamples/fastapi/README.mdexamples/fastapi/main.pyexamples/fastapi/requirements.txtexamples/fastapi/test_webhook.pyexamples/nextjs/.env.exampleexamples/nextjs/README.mdexamples/nextjs/app/webhooks/statsig/route.tsexamples/nextjs/package.jsonexamples/nextjs/vitest.config.tsreferences/overview.mdreferences/setup.mdreferences/verification.md

FAQ

Что делает скилл statsig-webhooks?

Receive and verify Statsig Event Webhook (Generic Webhook) requests. Use when setting up a Statsig webhook handler, debugging Statsig signature verification, or processing exposure events and config-change notifications (feature gates, experiments, dynamic configs).

Как установить скилл statsig-webhooks?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл statsig-webhooks запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить statsig-webhooks с