Functions

Signed payloads and webhooks

Payload signature verification is independent of caller authentication. Use built-in CubiBase HMAC-SHA256 for your own senders, or verify a provider’s scheme (Stripe, GitHub) inside your function against the exact raw body.

Three signature settings

SettingVerified byUse for
noneNobody — authentication mode still appliesJWT/API-key protected endpoints
hmacThe gateway, before your code runsYour own servers and services sending webhooks
customYour function code, using request.body and request.headersStripe, GitHub and other providers with their own schemes

Built-in HMAC-SHA256

When HMAC mode is enabled, the gateway rejects any request without a valid signature. The signed input is timestamp + "." + nonce + "." + rawBody, HMAC-SHA256 with the function’s signing secret, hex-encoded.

HeaderValue
x-cubibase-timestampUnix seconds; must be within the tolerance window (default 300 s)
x-cubibase-nonce16–128 chars of [A-Za-z0-9._-], single use per function
x-cubibase-signaturehex(HMAC_SHA256(secret, ${timestamp}.${nonce}.${rawBody}))
Sign a delivery from your server
import { createHmac, randomBytes } from 'node:crypto';

const body = JSON.stringify({ order: 4711, total: 4200 });
const timestamp = String(Math.floor(Date.now() / 1000));
const nonce = randomBytes(16).toString('hex'); // 16–128 chars, single use
const signature = createHmac('sha256', process.env.CUBIBASE_SIGNING_SECRET)
  .update(`${timestamp}.${nonce}.`)
  .update(body) // EXACT raw bytes you send — never re-serialize
  .digest('hex');

await fetch('https://example-project.api.cubibase.com/functions/orders-hook', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'x-cubibase-timestamp': timestamp,
    'x-cubibase-nonce': nonce,
    'x-cubibase-signature': signature,
  },
  body,
});
  • Comparison is constant-time; the timestamp must be fresh; each nonce can be used once — replays are rejected with 401 signature_replayed.
  • The signing secret is shown once when you enable HMAC or rotate it, and stored encrypted. It is never returned by read APIs and never logged.
  • Rotation keeps the previous secret valid, so senders can roll over without dropped deliveries.

Stripe, GitHub and other providers

Third parties cannot satisfy a CubiBase-specific format, and the platform does not force one on them. Set authentication to public and signature mode to custom, then verify the provider’s own header inside your handler using request.body (the exact raw bytes) and request.headers.

  • Stripe: verify Stripe-Signature (t=timestamp, v1=HMAC) with your whsec_… signing secret, stored as STRIPE_WEBHOOK_SECRET. The Stripe Webhook template does this with the official SDK and handles event idempotency.
  • GitHub: verify X-Hub-Signature-256 (sha256=HMAC of the raw body) with the secret you configured on the hook. The GitHub Webhook template is ready to edit.
  • Reject invalid signatures with a 4xx before any side effects. Return a fast 2xx only after the work (or its durable record) succeeded.

Additional resources