What the HTTP-Redirect binding is
The HTTP-Redirect binding is one of the ways SAML 2.0 moves a message between two parties through the browser. It is defined in section 3.4 of the bindings specification. The sender puts the message in a URL and redirects the browser there with an HTTP 302 or 303 response, or a plain link.
It is the usual way an app starts sign-in: the user clicks sign in, and the app redirects them to the identity provider with an AuthnRequest in the URL. It is also used for logout requests and responses. It is not used for sign-in responses, which are too large for a URL and travel with HTTP-POST instead.
What goes in the URL
https://auth.example.com/realms/acme/protocol/saml
?SAMLRequest=fZJBT8MwDIXv%2BxVR7m26IkBEa6WyCVFpQMUG…
&RelayState=%2Fdashboard
&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256
&Signature=Qm9ndXMgc2FtcGxlIHNpZ25hdHVyZQ…| Parameter | Meaning |
|---|---|
SAMLRequest or SAMLResponse | The XML, raw-DEFLATE compressed, Base64-encoded and URL-encoded |
RelayState | Optional. An opaque value the other side sends back unchanged, at most 80 bytes |
SigAlg | Only when signed. The signature algorithm URI |
Signature | Only when signed. Base64 signature over the other parameters |
If the endpoint URL already has a query string, the SAML parameters are added to it. The identity provider reads them from the query, not from the path.
RelayState
RelayState lets the app remember something across the sign-in round trip, typically the page the user wanted before they were asked to sign in. The identity provider returns it with the response, untouched.
The bindings specification limits it to 80 bytes and says the sender should protect its integrity. In practice, apps store the real target on their side and send a short random key, then look the key up when the response arrives. Putting a full URL in RelayState and redirecting to it without checking is an open redirect.
In IdP-initiated sign-in there is no request, but a RelayState can still travel with the response. Keycloak lets you set one per SAML client, the IDP Initiated SSO Relay State, which the app can use to decide where to send the user.
How a redirect URL is signed
The XML of a redirect message carries no ds:Signature. Instead, the sender builds this exact string from the URL-encoded values, in this order and without any parameter that is absent:
SAMLRequest=<value>&RelayState=<value>&SigAlg=<value>It signs the string with its private key, Base64-encodes the signature, URL-encodes that, and appends it as Signature. The receiver rebuilds the string from the parameters exactly as they arrived in the URL and checks the signature with the sender’s certificate.
Because the signature covers the URL-encoded bytes, decoding and re-encoding the values on either side can change them and break the check, for example when one side encodes a character in lowercase hex and the other in uppercase.
What this tool does
Enter the identity provider’s endpoint, choose SAMLRequest or SAMLResponse, paste the message XML or an already encoded value, and add a RelayState. The tool deflates and encodes the XML, or checks that the encoded value inflates, then builds the full URL. It shows the URL length and the RelayState size, and warns when RelayState is over 80 bytes, when the parameter name does not match the message type, or when the XML still contains a signature.
Switching between XML and encoded value carries the message across, so you can move between the two forms.
What it does not do
It does not sign the URL. Signing needs the app’s private key, and the page does not ask for keys. If the identity provider requires signed requests, the URL from this tool will be refused, and the page says so. It does not open the URL or send anything; you copy it and open it yourself.
How to use it
- Find the identity provider’s single sign-on URL for the redirect binding in its metadata, for example with the SAML metadata viewer.
- Enter it as the endpoint.
- Paste an
AuthnRequestwhoseIssueris the app’s entity id and whoseDestinationis the endpoint. Start from the sample and change the URLs. - Add a RelayState if you want to test that it comes back.
- Copy the URL and open it in a private browser window.
- After sign-in, capture the response and read it with the SAML response decoder.
Use cases
Testing a new SAML client before the app is ready
When you register an app at an identity provider, a hand-built URL shows whether the identity provider accepts requests in the app’s name. If you see the sign-in page, the issuer and destination are right. Errors at this step are about the client registration, not the app.
Testing Keycloak as the identity provider
A Keycloak realm accepts redirect requests at https://<host>/realms/<realm>/protocol/saml. The Issuer must match the client id of a SAML client in the realm. If that client has Client signature required on, Keycloak refuses an unsigned URL; for a manual test, use a test client with the setting off, never a production one.
Reproducing a user’s problem
Decode the request from a failing sign-in with the SAML request decoder, change one thing, such as the NameID policy or ForceAuthn, rebuild the URL here and try again. This isolates which part of the request causes the error.
Starting logout
A LogoutRequest can be sent the same way. It needs the user’s NameID and session index from the assertion, and most identity providers require logout requests to be signed.
Common problems
- The identity provider cannot inflate the request: it was compressed with zlib or gzip instead of raw DEFLATE.
- The identity provider does not know the app: the
Issuerdiffers from the registered entity id. - The signature is rejected: the string was signed with values decoded or in another order, or with the wrong key.
- The URL is too long for a proxy or server: the message is large; use the POST binding.
- RelayState is lost or cut: it is over 80 bytes, or contains characters that were not URL-encoded.
Security notes
- URLs end up in browser history, proxy logs and analytics. Never put secrets or personal data in a SAML request or in RelayState.
- Validate RelayState on return. Do not redirect to whatever it contains.
- Identity providers should require signed requests from apps that can sign, and must send responses only to registered ACS URLs.
Building the URL in code
The same steps in a few lines of Node.js, for when you script tests:
const fs = require('node:fs');
const zlib = require('node:zlib');
const xml = fs.readFileSync('request.xml');
const value = zlib.deflateRawSync(xml).toString('base64');
const url = new URL('https://auth.example.com/realms/acme/protocol/saml');
url.searchParams.set('SAMLRequest', value);
url.searchParams.set('RelayState', '/dashboard');
console.log(url.toString());URLSearchParams encodes spaces as +, which is fine for unsigned requests because Base64 never contains spaces. For signed requests, build the query string yourself with encodeURIComponent, so the bytes you sign are exactly the bytes you send.
Redirect or POST for requests
| HTTP-Redirect | HTTP-POST | |
|---|---|---|
| How the browser gets there | A redirect or a link | An auto-submitting form |
| Compression | Raw DEFLATE | None |
| Size limit | Practical URL limits | None in practice |
| Signature | Separate Signature parameter | ds:Signature inside the XML |
| Visible in logs and history | Yes, in the URL | Less so, in the request body |
For an AuthnRequest, redirect is the common choice because it is simple and the request is small. Use POST when the request is large, or when the identity provider asks for XML-signed requests.