Validating the Webhook S2S
You can validate incoming LoyaltyPlay postbacks using two methods: source IP validation and HMAC-SHA256 signature verification. The sections below explain how to configure and use each method.
Validating Postbacks with an IP Whitelist
To validate a Webhook, verify the IP it's coming from in the HTTP header.
Here it is the list of IPs from where we send the Webhooks S2S to publishers. Use these IPs to avoid security issues and validate incoming postbacks.
168.63.37.145
20.54.96.37
13.70.194.104
34.146.139.91
34.54.234.115
34.54.248.253
34.64.93.62
34.47.93.43
34.84.180.208
48.209.163.104
4.207.193.125
48.209.162.122
34.140.72.20Securing X-Forwarded-For Header
When your service is behind a load balancer or reverse proxy, be aware of potential manipulation of the X-Forwarded-For header. This header is used to identify the originating IP address of the client connecting to the web server through an HTTP proxy or load balancer.
Risks:
Header Manipulation: Attackers can spoof the
X-Forwarded-Forheader to bypass IP restrictions.
Security Measures:
Trusting Proxies: Only trust headers from known proxies or load balancers. Each cloud platform adds the client IP address at a specific position in the
X-Forwarded-Forchain, which you should consider when validating the IP.AWS (ELB/ALB): AWS puts the true client IP at the beginning of the
X-Forwarded-Forlist.Google Cloud Platform (GCP): GCP adds the original client IP at the second-to-last position.
Azure: Azure load balancers append the real client IP at the last position.
Make sure to parse this header correctly depending on your cloud provider to avoid accepting a spoofed IP.
PHP Code Example for AWS:
Validating Postbacks with HMAC-SHA256 Signatures
Add the {signature} macro to your postback URL and every postback we send you will carry an
HMAC-SHA256 signature of its query parameters, computed with a secret only you and we know.
Verifying it lets you reject postbacks that did not come from us or that were changed on the way.
The feature is opt-in: postback URLs without {signature} keep working exactly as today.
1. Setup in the publisher dashboard
Step 1 — Generate your signing secret
Open the publisher dashboard and go to Settings page.
Below your API key, find the Signing secret section.
Click Generate secret.
Click Copy to copy your signing secret (64 hexadecimal characters), then store it securely on your server, for example in a secrets manager or an environment variable. You can return to this page to copy it again at any time.
Good to know:
One signing secret per account. The same secret is used to sign postbacks for both your global postback URL and each ad unit’s postback URL.
Generate it only once. The secret cannot be regenerated or rotated from the dashboard. If you suspect it has been exposed, contact your account manager.
Keep it confidential. Treat the secret like a password. Never include it in client-side code, URLs, or logs.
Step 2 — Add {signature} to your postback URL
On the Settings page, select the global postback or the ad unit whose postbacks you want to sign.
Add a query parameter with
{signature}as its entire value. You can choose any parameter name; the examples below usesig.Save your updated postback URL.
Example:
The macros other than {signature} are examples only. Use the macros listed in the Publisher macros table on the Settings page.
Rules for the macro:
✅ It must be the whole value of a query parameter
&sig={signature}
❌ It cannot be part of a longer value
&sig=v1_{signature}
❌ It cannot be in the path or the fragment
/postback/{signature}
✅ The encoded form is accepted too
&sig=%7Bsignature%7D
⚠️ Generate the secret before adding the macro. If the URL contains
{signature}but no secret exists yet, the postback is sent with the literal text{signature}(or%7Bsignature%7D) instead of a signature.⚠️ Respect the placement rule. If
{signature}is not the whole value of a query parameter, the postback cannot be signed correctly and is not delivered.
2. Verification on your server
What is signed
The signature covers only the query string of the postback URL, excluding the signature parameter itself. Scheme, host, path and (for POST postbacks) the request body are not signed.
Algorithm
Given the request you received:
Take the raw query string, exactly as received. Everything after
?. Do not URL-decode it: values are signed in their percent-encoded form, as they travel on the wire (e.g.Mozilla%2F5.0, notMozilla/5.0). Most frameworks decode query parameters automatically, so read the raw string (see the snippets below).Split it on
&intokey=valuepairs, ignoring empty segments. Split each pair on the first=. A parameter without=has an empty value (flagbecomesflag=).Remove the signature parameter (
sigin our example) and keep its value aside: that is the signature you received.Sort the remaining pairs by key, then by value, using a plain byte-wise (ordinal), case-sensitive comparison. Uppercase letters sort before lowercase (
B<_<a). Repeated keys are all kept.Join them as
key=valuewith&. This is the canonical string.Compute
HMAC-SHA256(key = secret, message = canonical string):use the secret as text (its UTF-8 bytes) — do not hex-decode it;
encode the result as lowercase hexadecimal (64 characters).
Compare it with the received signature using a constant-time comparison. Accept the postback only if they match.
Worked example
Secret: my-test-secret
Received request:
Pairs without sig
uid=u42, pid=abc123, ts=1758067200, amt=1.50
Sorted & joined (canonical string)
amt=1.50&pid=abc123&ts=1758067200&uid=u42
HMAC-SHA256, lowercase hex
66cfb453f06e3427fccb907be8150dbe2762585560bf0373fce8b43bfa05017b ✅
Example with encoded values (same secret) — note that nothing is decoded:
Received query
ua=Mozilla%2F5.0%20%28X%29&name=a%26b&sig=…
Canonical string
name=a%26b&ua=Mozilla%2F5.0%20%28X%29
Signature
0f73f47356b7bad9f2bb5167cb59945f1702caed58e26986f2746a175f68d4c5
Changing anything in the signed parameters (even amt=1.50 → amt=1.5) produces a different
signature. Use these two examples as test cases for your implementation.
Reference implementations
Use the example below for your server-side language. Always verify the raw query string without URL-decoding it.
3. Troubleshooting
You receive the literal {signature} / %7Bsignature%7D
The signing secret has not been generated yet (step 1).
Postbacks stopped arriving after adding the macro
{signature} is not the whole value of a query parameter.
Signature never matches
Query values were URL-decoded before signing; the secret was hex-decoded instead of used as text; pairs were sorted case-insensitively; the signature parameter was not removed from the canonical string.
Signature matches only for some postbacks
Values with special characters (spaces, /, &, …) are being decoded or re-encoded before verification.
Last updated