WaForgeDevelopers

Reference

Request signing (HMAC)

Every request WaForge sends to your feed, and every event you send to WaForge, is signed with your data feed secret using HMAC-SHA256. The secret itself never travels: only the signature does. One small function covers both directions.

Headers we send #

HeaderExample
WaForge-Signaturet=1762424160,kid=fs_k3j9x0aq1m2b7c,v1=5f0c... (t = Unix seconds, kid = your key id, v1 = 64 lower-case hex)
WaForge-Request-IdA UUID, unique per request (use it to block replays)
WaForge-TenantYour public tenant id wf_tn_... (informational)

Canonical string and algorithm #

Pseudo-code
base = t + "\n" + METHOD + "\n" + path_and_query + "\n" + hex(sha256(raw_body))
v1   = hex(hmac_sha256(key = feed_secret, message = base))
  1. t: Unix time in seconds from the header. It must match ^[1-9][0-9]*$ (no leading zero) and v1 must match ^[0-9a-f]{64}$ (lower case). Reject anything else, and reject if |now - t| > 300.
  2. METHOD: upper case, GET or POST.
  3. path_and_query: the request target exactly as received, for example /waforge/catalog/search?q=black%20shoes&limit=5. Do not decode, re-order or drop the query.
  4. raw_body: the exact bytes received, before JSON parsing. Empty for GET (its SHA-256 is e3b0c442...b855).
  5. key: the whole secret string wf_fs_... as UTF-8 bytes (do not base64-decode it).
  6. Compare your hex result with v1 in constant time. During a rotation accept the current or the previous secret.
  7. Refuse bodies over 1 MB with 413 before reading them, and never verify with a blank secret.

Timestamp tolerance #

Accept a request only when |now - t| <= 300 seconds. Exactly 300 seconds old is still valid; 301 is not. Keep your server clock on NTP: a clock that is 5 minutes off rejects every request. The feed checker sends a request signed 10 minutes ago and expects 401.

Replay protection #

Inside the 300 second window, a captured request could be sent again. Block that by remembering (int) t + ":" + expected_v1 for 600 seconds with an atomic add (Redis SET key 1 NX EX 600, APCu apcu_add, Laravel Cache::add, a unique database key) and refusing the request when the key already exists. Use the signed values, never an unsigned header such as WaForge-Request-Id. The PHP, Laravel, Node, WordPress, Flask and Django kits do this; the Go and Ruby helpers give you ReplayKey / replay_key to store yourself.

Reference implementations #

PHP
function waforge_verify(string $header, string $secret, string $method, string $pathAndQuery, string $body): bool
{
    parse_str(str_replace(',', '&', $header), $p);           // t, kid, v1
    if (!preg_match('/^[1-9][0-9]*$/', $p['t'] ?? '') || !preg_match('/^[0-9a-f]{64}$/', $p['v1'] ?? '')) return false;
    if (abs(time() - (int) $p['t']) > 300) return false;
    $base = $p['t'] . "\n" . strtoupper($method) . "\n" . $pathAndQuery . "\n" . hash('sha256', $body);
    return $secret !== '' && hash_equals(hash_hmac('sha256', $base, $secret), $p['v1']);
}
// waforge_verify($_SERVER['HTTP_WAFORGE_SIGNATURE'] ?? '', $secret, $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], file_get_contents('php://input'));
Node.js
const crypto = require('crypto');
function verify(header, secret, method, pathAndQuery, rawBody) {
  const p = Object.fromEntries(header.split(',').map((s) => s.trim().split(/=(.*)/s).slice(0, 2)));
  if (!/^[1-9][0-9]*$/.test(p.t || '') || !/^[0-9a-f]{64}$/.test(p.v1 || '')) return false;
  if (!secret || Math.abs(Date.now() / 1000 - Number(p.t)) > 300) return false;
  const base = `${p.t}\n${method.toUpperCase()}\n${pathAndQuery}\n${crypto.createHash('sha256').update(rawBody).digest('hex')}`;
  const expected = Buffer.from(crypto.createHmac('sha256', secret).update(base).digest('hex'));
  const given = Buffer.from(p.v1);
  return expected.length === given.length && crypto.timingSafeEqual(expected, given);
}
Python
import hashlib, hmac, re, time

def verify(header: str, secret: str, method: str, path_and_query: str, body: bytes) -> bool:
    p = dict(x.strip().split("=", 1) for x in header.split(",") if "=" in x)
    if not secret or not re.fullmatch(r"[1-9][0-9]*", p.get("t", "")) or not re.fullmatch(r"[0-9a-f]{64}", p.get("v1", "")):
        return False
    if abs(time.time() - int(p["t"])) > 300:
        return False
    base = f"{p['t']}\n{method.upper()}\n{path_and_query}\n{hashlib.sha256(body).hexdigest()}"
    expected = hmac.new(secret.encode(), base.encode(), hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, p["v1"])

Go, Ruby and C# versions are in generic.zip.

Test vectors #

Use these to unit-test your code. Secret: wf_fs_test_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8, key id fs_test_01. Check with now = t. Download all: test-vectors.json.

1. GET catalog search with query string

Input
t = 1762424100
method = GET
path_and_query = /waforge/catalog/search?q=black%20shoes&limit=5
body = (empty)
Base string (\n shown as line breaks)
1762424100
GET
/waforge/catalog/search?q=black%20shoes&limit=5
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
WaForge-Signature
t=1762424100,kid=fs_test_01,v1=1b9f80ee3e072d71b0e68494a5fb4a588d4ef6b1969060d87b814a2b5d4f43e2

2. GET product by id (empty body)

Input
t = 1762424100
method = GET
path_and_query = /waforge/products/p_1001
body = (empty)
Base string (\n shown as line breaks)
1762424100
GET
/waforge/products/p_1001
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
WaForge-Signature
t=1762424100,kid=fs_test_01,v1=6c63ecb90276a74ce04464bb48a32370d92561062a348c2e114b7601c9164d01

3. POST availability JSON body

Input
t = 1762424160
method = POST
path_and_query = /waforge/availability
body = {"items":[{"product_id":"p_1001","variant_id":"v_42","quantity":2}]}
Base string (\n shown as line breaks)
1762424160
POST
/waforge/availability
08ddd28d177661bf93e4dbef212132abebf28d551d6910ce6f10f0009868fd3c
WaForge-Signature
t=1762424160,kid=fs_test_01,v1=6938bbcd2127c333d5c8e5febd5184b14cd3c17edec4accbe8760337a84bb44e

4. POST order lookup with UTF-8 body

Input
t = 1762424200
method = POST
path_and_query = /waforge/orders/lookup
body = {"order_number":"CMD-2041","phone":"+213550123456","note":"طلب"}
Base string (\n shown as line breaks)
1762424200
POST
/waforge/orders/lookup
83b2c31350cdc7bbde8298e5bedf1f74b2cd07602911a39c8aed682f22f91c6c
WaForge-Signature
t=1762424200,kid=fs_test_01,v1=20ca176e6622519070ea72e04e78a9eda5901f7d1f231e6f886e5bc01ddb20b7

5. PHP drop-in route in the query string

Input
t = 1762424300
method = GET
path_and_query = /waforge-feed.php?r=products/by-sku/TS-RED-M
body = (empty)
Base string (\n shown as line breaks)
1762424300
GET
/waforge-feed.php?r=products/by-sku/TS-RED-M
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
WaForge-Signature
t=1762424300,kid=fs_test_01,v1=148b524d75f0ba6359eba5440a1e762b04c98b3ddb1f0ef5871e7f559fb65ab0

6. Event pushed to WaForge

Input
t = 1762424400
method = POST
path_and_query = /api/v1/connect/events
body = {"id":"evt_123","type":"stock.changed","occurred_at":"2026-11-06T10:15:00Z","data":{"product_id":"p1","variant_id":"v1","quantity_available":0,"status":"out_of_stock"}}
Base string (\n shown as line breaks)
1762424400
POST
/api/v1/connect/events
0de5cc27cdd9c779c70f3898d498ee959737b0311598e87d4f3d85de60e8fc2b
WaForge-Signature
t=1762424400,kid=fs_test_01,v1=3f0f25cfe0d1ebc7c492139eebb6f905bebdbc44275f4a9e9840b541485e5511

Must be rejected

CaseWhy
wrong secretsignature mismatch
body changed by one bytesignature mismatch
timestamp 301 s in the pastoutside 300 s window
timestamp 301 s in the futureoutside 300 s window
path differs (query dropped)signature mismatch
timestamp with a leading zero (non-canonical t)t must match ^[1-9][0-9]*$
signature in upper case (non-canonical v1)v1 must match ^[0-9a-f]{64}$
upper case key name V1the key is v1, lower case
Exactly 300 s oldMust still be accepted (the limit is inclusive)

Key rotation #

  • Feed secrets start with wf_fs_ (32 random bytes, base64url). They are shown once in the dashboard; WaForge stores them encrypted with a key separate from the application key.
  • Rotate any time with New secret on your feed's page. WaForge keeps your two most recent secrets and signs its requests with the newest one immediately. Deploy the new secret to your site right away; until you do, your feed answers 401 and the agent hands chats to you.
  • Your site may accept two secrets during the change: Laravel WAFORGE_FEED_SECRET_PREVIOUS, Node previousSecret, WordPress "Previous secret" (dropped after 24 h, or at once with "Clear previous secret now"). The single PHP file accepts one secret.
  • Events you send to WaForge are accepted when signed with either of your two most recent secrets, identified by kid.
  • Never put the secret in browser code, a public repository or a URL. Rotate it if it may have leaked.