← Push Notifications / Authenticating Push Notifications with JWT

Authenticating Push Notifications with JWT

SIGNiX can secure push notifications with a JSON Web Token (JWT). When JWT is turned on, each push carries a signed token. Your server verifies the token to confirm the push came from SIGNiX. JWT is an alternative to the current push authentication. Added in SIGNiX Release 185.

Before you start

  • Currently available only in the Webtest environment. JWT push authentication is part of Release 185.
  • SIGNiX has to configure JWT for your account. It applies to the whole account and can't be set on a single transaction.
  • Webtest and Production use different keys.

How it works

  • SIGNiX generates a private key and a public certificate for you, and sends you the public key to install on your system. See Keys and certificates.
  • A JWT-secured push is an HTTP POST. An unsecured push is still a GET with query parameters.
  • The POST body is JSON only, sent with Content-Type: application/json.
  • The token is in the Authorization header. Do not expect Bearer before it. The header holds the token alone.
  • Respond with HTTP 200 to acknowledge the push. SIGNiX treats any 200 as success. It logs the response body but does not compare it to any value, so you do not need to return OK. Any other status is a failed push and is retried. See Retries.
  • A transaction's TransactionClientNotifyURL overrides the URL set for your client, as with any push. If your account is configured for JWT, the push to that URL is also sent as a JWT-secured POST.
  • Each attempt, including a retry, gets a new token with a new jti and iat.

Token format

Tokens are signed with RS256 (RFC 7519 and RFC 7518). The token header looks like this:

{"alg":"RS256","typ":"JWT","kid":"<key name>"}

The claims are:

ClaimValue
issSIGNiX (configurable)
subYour client ID (configurable)
audYour client ID (same as sub)
jtiA random UUID, new for every token
iatTime issued, in seconds since the epoch
expTime the token expires, in seconds since the epoch. The lifetime is currently 5 minutes and is configurable.

No other claims are sent with push notifications. SIGNiX Operations recommends standard values for iss, sub and aud. You can ask for different values.

Keys and certificates

  • SIGNiX Operations sends you the public certificate in X.509 format. There is no JWKS URL.
  • SIGNiX sets the kid value based on what your integration needs. It is the external name for the key.
  • Webtest and Production use different keys.
  • Rotation: SIGNiX Operations tells you when your public certificate is about to expire, and sends the new certificate before it takes effect. Old and new keys do not overlap. You are responsible for managing both the old and the new certificate.

Verifying a token

  1. Split the token into its three parts.
  2. Require alg to be RS256. Never use the algorithm the token names to decide how to verify it.
  3. Use kid to find your public key.
  4. Verify the signature over the original <header>.<claims> text, exactly as received. Do not parse and re-serialize it first.
  5. Check exp, iss and aud, allowing a small clock skew.
  6. If any step fails, reject the push.

What the token does and doesn't prove

The signature covers only the header and claims. It does not cover the URL, query string or body. A valid token shows the push came from SIGNiX, but it does not prove the body was unaltered. Don't rely on the token for body integrity.

Guarding against replays

If you want replay protection, track an identifier from the message body, such as the transaction ID, combined with the event type. Do not use jti for this, because a retry never reuses a token. You can still use jti to reject a repeated copy of the same token, but that is rare.

Retries

If your server responds with anything other than HTTP 200, the push fails and is rescheduled. The NotifyClientResendSchedule client preference controls the number of retries and how often they happen. It is currently set to retry 3 times, every 5 minutes, for all clients. Other settings have not been tested. SIGNiX does not look at the response beyond the status code. See Notification Failure & Retries for how failed pushes are queued.

Every attempt gets a fresh token, with a new iat, exp and jti. This includes a retry after your server rejected an expired token.

Common pitfalls

  • Trusting the token's alg instead of requiring RS256.
  • Re-serializing the JSON before verifying the signature.
  • Treating exp as a date string. It is seconds since the epoch.
  • Rejecting valid tokens because of small clock differences between servers.
  • Assuming one token per request. Retries carry a new token.
  • Using jti to detect duplicate events. Each retry has a new jti.
  • Responding with anything other than HTTP 200 after you have accepted the push. Any other status is a failure and is retried.
  • Not using a real JSON parser. Treat a parse error as a failed verification.

Checklist

  • Public key installed.
  • Authorization header read without Bearer.
  • RS256 required.
  • Key found by kid.
  • Signature checked on the original text.
  • exp, iss and aud checked.
  • HTTP 200 returned to acknowledge the push.