Server-side verification
The browser never decides anything: it carries proof to your backend. There are three ways to check it, from the simplest to the one with no network call at all.
| Way | Network call | What you get | When to use |
|---|---|---|---|
POST /v1/verify | 1, with sk_ | summary: visitor, score, risk, bot | quick start |
| local token | none | the same summary | high volume, minimum latency |
| sealed result | none | the whole event, every signal | fine-grained rules without an extra call |
GET /v1/events/:requestId | 1, with sk_ | the whole event | auditing, fine-grained rules |
1. Through the API
curl -X POST https://siftil.com/v1/verify \
-H 'authorization: Bearer sk_…' -H 'content-type: application/json' \
-d '{"token": "rst1.…"}'{ "valid": true, "rid": "fd15e76e…", "vid": "rv_2fa950ff…", "ss": 15, "risk": "high", "bot": false, "new": true, "iat": 1795314726 }A tampered token, one from another account, or one older than 10 minutes returns { "valid": false } with status 400.
2. Token checked locally
The token has the format rst1.<body>.<signature>:
body= base64url of the JSON{ rid, vid, ss, risk, bot, new, iat };signature= base64url(HMAC-SHA256(token secret,"rst1." + body)).
Get the token secret from the dashboard (or GET /v1/account → tokenSecret).
Node, Bun, Deno, Workers
import { createHmac, timingSafeEqual } from 'node:crypto'
export function verifySiftil(token, secret, maxAge = 600) {
const [v, body, sig] = String(token).split('.')
if (v !== 'rst1' || !body || !sig) return null
const want = createHmac('sha256', secret).update('rst1.' + body).digest('base64url')
if (want.length !== sig.length || !timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return null
const p = JSON.parse(Buffer.from(body, 'base64url').toString())
return Date.now() / 1000 - p.iat <= maxAge ? p : null
}Python
import base64, hmac, hashlib, json, time
def verify_siftil(token: str, secret: str, max_age: int = 600):
try:
v, body, sig = token.split('.')
except ValueError:
return None
if v != 'rst1':
return None
want = base64.urlsafe_b64encode(hmac.new(secret.encode(), f'rst1.{body}'.encode(), hashlib.sha256).digest()).rstrip(b'=').decode()
if not hmac.compare_digest(want, sig):
return None
p = json.loads(base64.urlsafe_b64decode(body + '=' * (-len(body) % 4)))
return p if time.time() - p['iat'] <= max_age else NoneGo
func VerifySiftil(token, secret string, maxAge int64) (map[string]any, bool) {
parts := strings.Split(token, ".")
if len(parts) != 3 || parts[0] != "rst1" {
return nil, false
}
m := hmac.New(sha256.New, []byte(secret))
m.Write([]byte("rst1." + parts[1]))
want := base64.RawURLEncoding.EncodeToString(m.Sum(nil))
if !hmac.Equal([]byte(want), []byte(parts[2])) {
return nil, false
}
raw, err := base64.RawURLEncoding.DecodeString(parts[1])
if err != nil {
return nil, false
}
var p map[string]any
if json.Unmarshal(raw, &p) != nil {
return nil, false
}
iat, _ := p["iat"].(float64)
return p, time.Now().Unix()-int64(iat) <= maxAge
}PHP
function verify_siftil(string $token, string $secret, int $maxAge = 600): ?array {
$p = explode('.', $token);
if (count($p) !== 3 || $p[0] !== 'rst1') return null;
$b64u = fn($s) => rtrim(strtr(base64_encode($s), '+/', '-_'), '=');
if (!hash_equals($b64u(hash_hmac('sha256', 'rst1.' . $p[1], $secret, true)), $p[2])) return null;
$data = json_decode(base64_decode(strtr($p[1], '-_', '+/')), true);
return (time() - $data['iat'] <= $maxAge) ? $data : null;
}3. Sealed result
server.sealed is the whole event encrypted with AES-256-GCM: rss1.<base64url(12-byte iv ‖ ciphertext ‖ 16-byte tag)>. The AES key is the SHA-256 of your seal key (as text). Only whoever holds the key can open it; the browser just carries it.
import { createHash, createDecipheriv } from 'node:crypto'
export function unsealSiftil(sealed, sealKey) {
if (!sealed.startsWith('rss1.')) return null
const b = Buffer.from(sealed.slice(5), 'base64url')
const key = createHash('sha256').update(sealKey).digest()
const d = createDecipheriv('aes-256-gcm', key, b.subarray(0, 12))
d.setAuthTag(b.subarray(b.length - 16))
return JSON.parse(Buffer.concat([d.update(b.subarray(12, b.length - 16)), d.final()]).toString())
}# pip install cryptography
import base64, hashlib, json
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
def unseal_siftil(sealed: str, seal_key: str):
b = base64.urlsafe_b64decode(sealed[5:] + '=' * (-len(sealed[5:]) % 4))
key = hashlib.sha256(seal_key.encode()).digest()
return json.loads(AESGCM(key).decrypt(b[:12], b[12:], None))The sealed event has the same format as GET /v1/events/:requestId (see Event). Check t (milliseconds) so you do not accept an old event, and store the requestId so you do not accept the same one twice.
How to decide
A starting rule that works for most signups:
const e = unsealSiftil(body.siftilSealed, process.env.SIFTIL_SEAL_KEY) // or GET /v1/events/:id
if (!e || Date.now() - e.t > 10 * 60_000) return requireVerification()
if (e.suspect.risk === 'high') return blockOrReview(e.suspect.reasons)
if (e.signals.multiAccount) return limitFreeTrial(e.visitorId)
if (e.suspect.risk === 'medium') return requireVerification() // e-mail, SMS
return allow()- Do not block on
mediumalone: corporate VPNs, incognito and a different time zone are common among honest people. Ask for one more check. - Use the
visitorIdas the limit key: one free trial per device, N signups per device per day. - Store
requestIdandvisitorIdin your table of signups and orders. Labelling later and answering chargebacks becomes easy. - Institutional networks: hospitals, companies and universities show up in
signals.network. Many users on one IP is normal there, and the score already does not punish it.
Siftil · API v1 documentation